Wednesday, December 3, 2014

AngularJS Fundamentals In 60-ish Minutes

AngularJS Fundamentals In 60-ish Minutes



- $Scope : Glue between Controller and View.
         : $Scope is ViewModel

- ViewModel : Data for the View or Model for View

- Controllers (in MVC) should not know about View as this makes it depend on View. This allows Controllers to be testable and Multiple Views are possible this way.

- Modules : are containers

- Routes : Maps View and Controller

Tuesday, December 2, 2014

Dependency Injection ( and Dependency Injection Container)

Video : http://www.youtube.com/watch?v=IKD2-MAkXyQ

Dependency : Dependency is has a relationship. Class A has class B. Class Cycle has Tyre.

Injecting Dependency : Dependency is pushed from outside to the class. So in above example Class Cycle instead of instantiating instance of class Tyre, gets an instance of Tyre from outside.

Principal Behind Dependency Injection : We should code to abstractions (interfaces).

Dependency Injection Container Pattern : Used to create dependencies for class\es.  Knows which class has which dependencies and how to instantiate those dependencies.


Tuesday, October 7, 2014

Utilizing SysteInternals (Channel 9 Course : http://channel9.msdn.com/Series/sysinternals/01)

Mod 1 : Introduction (http://channel9.msdn.com/Series/sysinternals/01)

  • Imp SysInternals tools 
  1. ProcessExplorer (Most Popular)
  2. ProcessMonitor  (Most Popular)
  3. PSTools
  4. AutoRuns

Could be used
  1. as Advance (IT Pro) version of Task Manager.
  2. to see all Threads associated with a Process
  3. to see Stack Trace, Number of Context Switches of a Thread
  4. to check which Process is having handle for a File.
  5. to check if a Process has open TCP-IP connections. Shows to which IP addresses current Process is connected to.
  6. Process Explorer (like many other SysInternals tools) can connect to a remote machine and show Process information for that machine.
  7. Process Explorer could be configured so that whenever user sees Process Explorer instead of System Task Manager.
  8. When an error message is shown and its source is not known. Bullet Eye functionality could be used  could be used to see which Process is associated with that message.
  9. SvcHost.exe is service host process. Process Explorer shows additional tab called Services in Properties window for Process Explorer. Process Explorer could be used to see which services are hosted by given instance of SvcHost.exe
  10. Good practice to Add columns Version, Integrity and Virtualized to Process Explorer.
  11. Microsoft doesn't Test Windows with disabling IPv6. So do not disable it without thorough testing.
  1. This tool is combination of FileMon (File Monitor) and RegMon(Registry Monitor).
  2. When to use Process Monitor : DLL corruptions, Configuration issues, Performance Diagnostics,
  3. By default Process Monitor displays Activities in Registry,File System, Processes (Process, Thread, DLL and Device Driver load operations) and Profiling (User and Kernal CPU time consumed, Number of context switches).  Networking (TCP and UDP network activity including source and destination address).
  4. 'Boot Monitoring' : Enabling this start Process Monitor on boot. Process Monitor will collect Trace since boot. 
  5. Process Activity Summary : 
"PSExec.exe \\RemotePC cmd" This command will start command prompt on remote machine named RemotePC. Subsequent commands entered in command propmt will actually be run against RemotePC.
  • PSInfo : Gives information of the system. Could be run remotely.
  • PSFile :
  • PSKill : Enables killing process on remote machines 
  • PSService : Displays Configuration,Dependencies and Status of Windows services.
  1. Very useful application to run automatically running application. Shows Applications which run on Logon, Services which run on Startup, Scheduled Tasks and many more.

Wednesday, August 6, 2014

Channel9 Podcast : Entity Framework Tips and Tricks


  • Video URL
  • Entity Framework PowerTools : Shows conceptual model used by DBContext (Which is very relevant for Code-First Model).
  • DBContext API simplified wrapper around ObjectContext API. ObjectContext being detailed one.
  • Explore (in QucikWatch window) ObjectContext.ObjectStateManager to see what all changes have happened so far.

     Important methods in EF (Not covered in above Video)
  • AsNoTracking() : Fetches entities from database in Non- Tracking mode. So changes to the entities won't be tracked.
  • ToTraceString() : This method could be used to find out corresponding SQL statement which would be executed by given Entity Framework query.
  • Translate() : Converts result in DataReader (or DataTable) into Entities. Entities are not added to context by this method call. If you some code in pure ADO.NET and you don't have time or resources to redo it in EF (or it's way easier old way) you can rewire the result into existing objects. 

Wednesday, July 23, 2014

VSTS Data Driven Tests


- Set TestMethod's Dataconnection property to CSV file. CSV file contains test data and expected outcome.
- int x = Convert.ToInt32(TestContext.DataRow["x"]);
This will fetch current value for variable x from Test data file.

Saturday, February 8, 2014

IIS For Developers

IIS 7 / 7.5
  • Version of IIS is always tied to version of OS.
  • Modularity of IIS 7 /7.5: You chose modules of IIS which are to be installed.
  • SSL Site: A unique IP address is required for SSL enabled web site.IIS cannot use Host name to distinguish, because host name is encrypted when IIS handles request.
  • Starting IIS 7 certain settings are saved in Application’s web.config file.Each App pool has one worker process.
  • Starting IIS 7: When you create a new web site, IIS creates a new App pool of exact same name.
  • Managed Pipeline mode:  Use Integrated mode if possible.
  • Unhandled exceptions lead to App pool to crash.
  • Any type of configuration change leads to an App pool to recycle.
  • Session state is saved in App pool. So when App pool is recycled session state would be lost?  
  • IIS Troubleshooting
                                    -  Find slow running pages in runtime using worker processes module
                                     - Track errors using Failed Request Tracing module
  • Log Parser Wizard & Log Parser Tool are could be used to analyze log files. Log Parser Tool allows SQL like queries on log.
  • MSDeploy is a tool from Microsoft for deploying web sites.
  • MSDeploy could be used
                    - To sync two web servers.
                            - Take back-up of site on physical drive and vice versa.
                            - Since Visual Studio 2010. MSDeploy is built in to VS 2010.
  • URL Rewrite extension: Could be used to give friendly URLs to user. This is IIS feature.
  • Web Farm Framework: There is IIS extension which helps in Web Farm.

IIS 8
  • Application Initialization: When first user shows up, lot of initialization happens. Application initialization allows this to be done before first user shows up. Thus first user won't take hit.
  • SNI: Allows multiple SSL certificates to one IP Address.

.Net Regular Expression

Regular Expressions

• With .Net Regex you need to think about efficiency first.

• Regex class supports two flavors of Regular Expressions

  1. Full featured .Net version
  2. ECMA (JavaScript) version

• Outcome of Regex.Match can tell which part of subject matched which parts of pattern.

• Concatenation, Alternation (|), Repetition (*)

• Regex is immutable class.

• Regex finds leftmost match.

• Alternation: Order of terms in alternation is important (catnip|cat) will match catnip first and if this didn’t match then it will match cat.

• Repetition

  1. Group a set of characters together using parenthesis for e.g. (cat)* matches all multiple occurrences of cat.
  2.  (cat)* : Match 0 or more
  3. (cat)? : Match 0 or 1
  4. (cat)+ : Match 1 or more
  5. (cat){1, 4}: Minimum 1 and maximum 4 occurrences are to be matched. 


Matching whole Expressions

• Match.NextMatch gives next match.

• (?m) : End modifier. This says that subsequent Regex is multiline regular expression.

• \A : Match start of the string. This is not affected by End modifier.

• ^: Same as \A if regular expression is not multiline. Matches subsequent pattern only at the start of new line.

• $: (Opposite of ^) When regular expression is not multiline, match should end with string end. When regular expression is NOT multiline, match should end with newline.

• \Z: (Opposite of \A) is not affected by End modifier. Match end of string.

• Custom character class e.g. [abc]

• Custom character class is more efficient than alternatives i.e. [abc] is more efficient than a|b|c. That’s why character classes are preferred over alternations if possible.

• Character class matches single character only.

• [a-z0-9] : All characters from a to z and 0 to 9

• [^a-z]: All characters except a to z. ^ is negation in this context.

• /d : [0-9]

• /D: [^0-9] (Note negation, so all characters except 0 to 9.

• /s: Any white space character

• /S: Negation of /s

• /w: a to z, A to Z, 0 to 9 and underscore and few more characters which are part considered to be part of English word

• /W: Negation of /w

• \w{3}: Match exactly 3 word characters

• \ is escape character. Regex.Escape method will add escape characters wherever necessary.

• \b: Word boundary. Matches with start or end of the word.

• \B: Negation of \b

• . (Dot): Wild character. Matches any character. By default won’t match New line.

• (?s) : Dot Modifier. (Dot) will match new line character as well. (:) colon is used to scope modifier to only one alternation pattern. For e.g. (?s: c.t) | d.g : Here modifier is applied only to first clause of the pattern.

• Avoid using operator * on . (dot) for performance reasons.


Saturday, January 18, 2014

Thumb Rules for building secure web sites



  1. Don't trust user input. 
  2. Filter input as it comes in,  and accept only what you know is good. i.e Check for white box and black box.
  3. Encode untrusted data before outputting it to your http stream.