Posts

MVC 4 Best Practices

Use the NuGet Package Manager to Manage Dependencies The NuGet package manager is a great boon to developers and teams alike. Instead of spending your time getting up and running and checking to see if the projects that your application depends on have released new versions, let NuGet handle all of that for you! If your organization has several teams that share common libraries, consider creating custom NuGet packages for those shared libraries and hosting a custom NuGet repository to provide more effective distribution and versioning. Depend On Abstractions Abstractions encourage loosely-coupled systems with a healthy separation of contracts and implementations. Abstractions are easily interchanged which not only provides easier maintenance, but is also crucial to unit testing. Avoid Referring To HttpContext Directly (use HttpContextBase) ASP.NET MVC (and later, .NET 4) introduced System.Web.Abstractions, a set of abstractions over many of the core parts of the ASP.NET F...

Handy way of splitting comma separated values in T-SQL without using a function

I came across this situation wherein a need to split a comma separated value and insert it to the database, one by one. here's the solution to the problem. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 CREATE PROCEDURE ppm_InsertDealerContactsReportXref -- Add the parameters for the stored procedure here @ dlrcxIddlrc INT = 0 , @ dlrcxIdcl VARCHAR ( 300 ) AS BEGIN SET NOCOUNT ON ; DELETE FROM dbo.rpm_DealerContactsReportXref WHERE dlrcxIddlrc = @ dlrcxIddlrc DECLARE @ DealerContactsReportXref TABLE ( dlrcxIddlrc INT ,dlrcxIdcl VARCHAR ( 100 ) ) INSERT INTO @ DealerContactsReportXref ( dlrcxIddlrc ,dlrcxIdcl ) VALUES ( @ dlrcxIddlrc , @ dlrcxIdcl ) INSERT INTO rpm_DealerContactsReportXref ( dlrcxIddlrc ,dlrcxIdcl ) SELECT dlrcxIddlrc ,LTRIM(RTRIM(m.n.value( '.[1]' , 'varchar(8000)' ))) AS ids FROM ( SELECT dlrcxId...

Handy - Default Style in Step Definition in SpecFlow

Put this in App.config to make the default style method name underscores: <specFlow> <trace stepDefinitionSkeletonStyle= "MethodNameUnderscores" /> </specFlow>

Took a Codility Test : Decimal Reverse, Magnitude Pole and Most Number of Occurrence.

Image
I took a test few days ago in Codility, I say this really is a good way to validate the skill set of programmers, it shows clearly how they think and approach problem vs normal multiple choice type of question or by simply having a technical interview. Here's my answer to the Codility questions. Decimal Reverse: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 public static int DecimalReverse ( int n) { char [] arr = n.ToString().ToCharArray(); string reversed = string .Empty; List< string > list = new List< string >(); foreach ( var item in arr.Reverse()) { list.Add(item.ToString()); } reversed = string .Join( "" , list); return Convert.ToInt32(reversed); } Magnitude Pole: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 public static int MagnitudePole ( int [...

Creating an Automated Testing Framework using Selenium.

Instant T-SQL Formatter

Imagine you are maintaining an existing system, there are countless of SP's already in use, and there are few other devs touching the sp's every now and then, and normally they look it up via sp_helptext without pressing CTRL+T, they copy and paste the result, modify it and execute it. The result is SP having white spaces and not properly formatted, wouldn't it be nice if we can format it with a click of a button? Yes, there's a tool for that. I'm attaching a link to it giving credit to the the owner of the site and the one who created it. http://architectshack.com/PoorMansTSqlFormatter.ashx#Download_5

Identity vs Scope Identity vs Ident_Current

While doing some update on an existing Store Procedure I came across a code that retrieves an Identity value. 1 2 3 4 5 6 if @@ rowcount > 0 begin select @ id = scope_identity() end else select @ id = 0 Now let's discuss when to use Identity, Scope Identity and Ident_Current, I checked the internet and found an article from the SQL Authority . Here's a brief of what it says: Select  @@IDENTITY It returns the identity value generated on a connection regardless of table and the scope which produce the value, it means that in case a trigger was also called from the same connection and produced an identity, this identity will be returned. Select SCOPE_IDENTITY It returns the identity value generated on a connection and by a statement on the same scope regardless of the table the produced the value. it will return the value that was explicitly created by the statement and will not be affected by any trigger even if it creates an identity on the same ...