Taswar Bhatti
The synonyms of software simplicity
goliath

What the ???? goliath ERROR: While executing gem.
I was wanting to try out goliath.io (Goliath: Non-blocking, Ruby 1.9 Web Server) for more info look at http://www.igvita.com/2011/03/08/goliath-non-blocking-ruby-19-web-server/

In any case I was not able to get it to install on JRuby so went and get me 1.9.2 MRI.

Once installed MRI 1.9.2, I went into the gem dir to gem install goliath and guess what this message pops up.

Really helpful (scarcasim) , then what I had to do to fix this was update my gem

After doing so I was able to

Now its time to try out goliath, wish me luck and if anyone knows how to install it with Jruby please let me know cuz jgem install goliath didnt work for me.

delegate

Here is a nice little code I did recently, where the Command Pattern is used with a notification observer like pattern.

First of the Command Pattern, a simple interface for task with an execute method

Then the notification interface, with 2 methods, one when it started and one when its complete and the event delegate

Now the class that implements the interface, I used an abstract class so that I can just use a subclass to implement the simple task I wish to have

Now I can write a simple class that inherits from AbstractTask like this

Now to consume the task

This is more or less the simple form of creating a command pattern to run task that includes a notification to send back. It makes sense to have multiple task like creating users and running database scripts etc etc. This allows one to have flexible design and have an IEnumerable<AbstractTask> and run through each one with an execute method.

Hope this helps 🙂 Happy coding.

ASP.NET-MVC

Here is a simple trick on how to disable browser cache in asp mvc application with an attribute.
If you have a base controller just add this to your base and all your request would have Pragma No-Cache

Simply add this to your base controller, and you are done 🙂

ASP.NET-MVC

To enable https on asp.net mvc, one can use the [RequireHttps] attribute on the base controller if you are using a base controller

But what if you want to give an option to the installer or the client to enable it in web.config, the easy way to do it for asp mvc2 is to create your own property like code below: (Please note: I am using protected virtual to override stuff for testing, its not one of the best things but it works in breaking dependency and its quick, so that I dont have to mock httpcontext, configuration manager etc etc, I could use an IoC but would make it more complicated for the reader but feel free to use one)

Here is the unit test for it, I am using a stub class to override the things I want for testing

Now in your web.config you can add a key value pair like

And last if you are using Asp.Net Mvc3 life is way easier, one can just use in their Global.ascx file to add the filter

Lastly you would add it to your BaseController

jquery

Was debugging some code that was broken due to jquery 1.6 update, and found this call for Jquery dropdown.val

Not working anymore but a simple fix of changing it to

This does the trick, for more on prop take a look at the api of jquery http://api.jquery.com/prop/

MSSQL

So was hacking a new installer and wanted to display the data link properties dialog, for building a connection string.
Here is what I have found out by playing with it.
One has to add the reference to ADODB.DLL (from .NET reference) and Microsoft OLE DB Service Component 1.0 Type Library from the COM tab in your visual studio reference tab.

Here is some sample code, assuming that you have a button and a textbox on the screen.

And here is how it looks like

Once a user clicks on build, the Data Link Properties Shows up.

Data Link Properties Dialog

Also note: that I am providing some default into the connection, since if you do not provide “Provider=SQLOLEDB.1” then the default is just OLE database not the MSSQL database option.

Rubymine

In order to run Rubymine under a 64bit jvm one needs to run the IDE from the bat file.

In the bat file which is located at C:\Program Files (x86)\JetBrains\RubyMine 3.1.1\bin add this line

SET RUBYMINE_JDK=%ProgramFiles%/Java/jdk1.6.0_25

and remove the IF statements
::IF “%RUBYMINE_JDK%” == “” SET RUBYMINE_JDK=%JDK_HOME%
::IF “%RUBYMINE_JDK%” == “” goto error

Run the rubymine.bat file voila 64bit jvm.

Mocking

Thanks to everyone who came to Unit Testing with Mocking Framework at the code camp today, I will get those Typemock license to the 2 winners.

Here is the code if anyone is interested
https://github.com/taswar/Ottawa-IT-Code-Camp-Unit-Testing-with-Mocking-Framework

Here is the presentation.

VisualStudio

So I had this issue at work had to install on xp machine, dont ask why but just had to 🙂 and the error was NET 4, Visual Studio 2010 install fails on XP SP3 machine “Fatal error during installation”

Thus I was stuck installing Visual Studio 2010, I went and downloaded .net 4 standalone

And was having the same issues.

And went through the logs and found the error message was due a registry key (aren’t they always)

Product: Microsoft .NET Framework 4 Client Profile — Error 1402. Could not open key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Security\ServiceModel 4.0.0.0. System error 5. Verify that you have sufficient access to that key, or contact your support personnel.

So I went to regedit, went to that key and added Administrators rights to it and run the installer again and everything was fine and installed vs2010 and .net 4 finally…………….

Anywayz just in case anyone runs into this issue again, this was the solution.

browser testing

Thanks to everyone who came out for the Ottawa .Net Community talk yesterday on WatiN , SpecFlow, BDD, WebDriver, I had a blast. I would like to thank everyone who came out for the talk.

Here is my presentation

You can find the code on github
https://github.com/taswar/ODNC-WatiN-And-SpecFlow-Demo-Code

Additional Resources

Here are some additional information for people who wish to learn more Gherkin style of BDD. Cuke4Nuke provides a free pdf file on learning cucumber BDD although not specflow but gives you a good idea of learning it.

http://www.cuke4ninja.com/

Steve Sanderson has a blog post where he explains BDD style with WatiN and specflow
http://blog.stevensanderson.com/2010/03/03/behavior-driven-development-bdd-with-specflow-and-aspnet-mvc/

Brandon Satrom also has a series of video which shows how to use specflow with WatiN
http://userinexperience.com/?tag=/aspnet-mvc

UA-4524639-2