Programming

Select Random Records Using Nhibernate

Selecting 5 random rows in SQL is easy

Nhibernate is a different story.  I am new to NHibernate and I both love and hate it.  I hate the steep learning curve and the unobvious ways of doing things.  Anyway, here is how to select 5 random records using nhibernate. First class a new order(…)

Regular Express For Parsing URLs

I am always looking for this one, so I am blogging it for future reference and for everyone to use. ^(?#Protocol)(?:(?:ht|f)tp(?:s?)\:\/\/|~/|/)?(?#Username:Password)(?:\w+:\w+@)?(?#Subdomains)(?:(?:[-\w]+\.)+(?#TopLevel Domains)(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))(?#Port)(?::[\d]{1,5})?(?#Directories)(?:(?:(?:/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|/)+|\?|#)?(?#Query)(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?#Anchor)(?:#(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)?$ There is more information on Ivan’s blog.

Shortening URLs with bit.ly’s API in .NET

Shortening URLs with bit.ly’s API in .NET

I previously wrote about shortening URLs with TinyURL’s API but my new favorite URL shortener is http://bit.ly and it also has a great API that you can use from within your .net code.  I just recently used in my twitter contest website – tweetastica. The code is also very simple.  I didn’t add all the(…)

Themes and ASP.NET MVC

Themes and ASP.NET MVC

I wanted to easily add theme support to yonkly, so that others can install it and modify its look and feel as they please.  I also wanted it to be as easy as installing a theme in wordpress. I created a themes folder under the content folder Then I referenced my css file in the(…)

Mocking and Dependency Injection in ASP.NET MVC

Here is the situation, my controller constructors take multiple interfaces as parameters.  I do this in order to use constructor injection which allows me to inject the controllers with mocked objects in my unit tests. For example, my AccountController takes IEmailService, IFormsAuthentication and MembershipProvider (abstract class) as parameters. During my testing, I want to mock(…)