Friday, October 30, 2009

Linux shell scripts – name of script file

How to get the filename and directory name of the shell script being run:

directoryName=${0%/*} #capture everything before the last /
filename=${0##*/} #capture everything after the last /

Thursday, October 29, 2009

Types of brackets

Disambiguation of {braces parentheses brackets}
note: they are all types of brackets

from Wikipedia

  • ( ) - round brackets, open brackets or parentheses
  • [ ] - square brackets, closed brackets or box brackets
  • { } - curly brackets, squiggly brackets, swirly brackets, braces
  • < > - angle brackets, diamond brackets, cone brackets, wickets, chevrons

Wednesday, October 28, 2009

Windows port of some useful UNIX commands

Recently I came across the “Cut” and “Paste” commands in Linux. Man, these are useful tools as they allow you to rearrange your data from an existing file.

And now to make my life easier in Windows, I have found a SourceForge project that has ported many of these commands to Windows.

Find it at: Very Nice!

The list of UNIX/Linux commands available in the download I got:


Ubuntu + VirtualBox + low screen resolutions

If you run Ubuntu and you get only a low screen resolution of 800x600 (and not the native resolution of your host machine), then what you may need are the “Guest Additions”.

Here is what you need to do:

1. Run Ubuntu in VirtualBox

2. Use the host key to get to the host OS (normally the right ctrl key). This will allow you to move your mouse out into the world of your actual machine.

3. Click on "Install Guest Additions" under the devices menu:
This should load up a window that will display the contents of Guest Additions cd.
If you do not see the above disk on your Ubuntu desktop, then you might have to mount the guest additions. Here is how:
Go to Devices –> Mount CD/DVD-ROM –> CD/DVD-ROM Image…


Go to the CD/DVD Images tab and Click on Add.

Browse to the Virtual Box folder and select the “VBoxGuestAdditions.iso” file.
Click on Select on the “CD/DVD Images” tab.

You should get the CD for VBoxAdditions on your Ubuntu desktop now.

4. Double click the CD to view its contents. Which should look like this (and have some more files).

5. Depending on your host system you will have to run one of the “” files.

6. Unfortunately, its not as simple as double clicking the file to run it (as it needs to be run as an admin). Here is what you need to do:

Open a terminal prompt (Applications –> Accessories –> Terminal)

Navigate to the CD drive (type cd /media/cdrom0/)

Type LS and you should see all the files in the folder:

Type sudo sh ./ (remember its case sensitive)

You should be prompted for your password. Ubuntu should then run for a short while installing everything and you will be asked to restart.

Once you restart, you should get your native resolution. If not check the display settings.

Note: I had to install the Guest additions 2 times to get the new resolution in my Ubuntu virtual installation.

Note 2: Additional good stuff: Your mouse is no longer captured by Virtual box – which means you can seamlessly move between the host machine and the virtual machine. Also, copy paste will work across the 2 machines too. (Very nice!)

Monday, October 26, 2009


Get over the idea that only children should spend their time in study. Be a student so long as you still have something to learn, and this will mean all your life. ~Henry L. Doherty

The Google Story - 1995 to now

The Google Story - 1995 to now

Saturday, October 24, 2009

Personalize Windows 7

Themes, backgrounds, gadgets to make your Windows 7 computer your very own.

My vote is for “Bing’s Best” theme pack. Very nice.

Words - debouch


to march out from a narrow or confined place into open country, as a body of troops: The platoon debouched from the defile into the plain.

Physical Geography.

to emerge from a relatively narrow valley upon an open plain: A river or glacier debouches on the plains.

to flow from a small valley into a larger one.

to come forth; emerge.

Friday, October 23, 2009

Download YouTube video bookmarklet

via the GoogleSystem blog:

Here is a book-marklet that lets you download YouTube videos as MP4 files. (just drag the link on to your book-mark toolbar or right click and add to favorites).

Download YouTube Bookmarklet

Tuesday, October 20, 2009

DNN – Module Load Warning Error

Last week, one of my DNN installations all of a sudden started giving me the following error:


Typically, if you log in as an administrator, then you can view the error information. But in my case, I was unable to see any information. In fact, I was unable to log in to the DNN portal. Upon further investigation what I realized was that even the content was not being rendered.

The only information that I was able to find out was from the event log tables in the database, which had the following information:


So it looked like the error was being thrown in the “DotNetNuke.UI.Skins.Skin.InjectModule” method and it looked like a property or a method was being invoked on an object that was null. But the above information is not very helpful.

Without any other information, I decided to modify the DNN code so that I could add additional logging information to the InjectModule code to see what was going on. To do this, I decided to use a simple text file to log the information. VB.Net is not my primary development language so I had to look up the syntax to create a file in append mode:

Using writer As StreamWriter = New StreamWriter(Server.MapPath(".\log\") & "attempts.txt", True)
    'call code in here
    writer.WriteLine("log info using writeline")
End Using

Once I had the code modified to perform in-depth logging, I found out that the InjectModule method would use the LoadControl method to load a user-control into a page. But before that, it would need to create the container into which it needed to load the user control. In version 4.6.2 of the DNN code, the code never expects the container to be null (ctlContainer.FindControl(glbDefaultPane)) and in our case the ctlContainer object was turning up null and was causing the “Object reference not set to an instance of an object” error.

But why was ctlContainer turning up Null. Turns out some files in the “Portals\_default\Containers” folder and in the “admin\Containers” folder had gone missing. Unfortunately for us, even the default containers had gone missing and hence ctlContainer was turning up null.

I am not sure why the files in those folders got deleted (module mis-behaving, user error, etc), but it sure was hard to track down this bug and fix it. Luckily DNN is an open-source project and we were able to track down the issue by modifying the core code for this purpose.

Monday, October 19, 2009

ViewState, dynamically loaded User Controls and ASP.Net

If you find that your ViewState is unavailable to your user control in ASP.Net and if you loaded the user-control dynamically (using the LoadControl method), then check to make sure that you are dynamically loading the user-control in the OnInit method. Most people make the mistake of loading the user-control in the Page_Load method and the problem with that is that the state is loaded before the Page_Load method is called (see diagram below – Page_Load is the Load event). When the view state is loaded and processed, ASP.Net will look for the control and if it is there – it will fill it with the data from the view-state and if the control isnt available, then it will be ignored.

By loading the user-control in the Init event, you ensure that the control will be available when the LoadViewState method is called by the framework and it will then be filled out correctly with the values from the view-state. (This is usually followed by the Raise xxxx Events, where you typically check the value of the control to perform further processing).


If you find that the LoadViewState method is not being called, then it is most probably because your control it-self is not using the View-State. To ensure that it is called try and over-ride the SaveViewState method and save a dummy value to the view-state. After this the LoadViewState should begin getting called.

Friday, October 16, 2009

TFS – Work Item Manager

I was searching for a better taskboard to use with Team Foundation Server (TFS) than the one that comes canned with the Scrum for Team System (SFTS) template (which is a static report) and I came across the Work Item Manager.

In one word – its AWESOME!!!!

Work Item Manager is a beta product from Telerik and it does much, much more than just being an interactive task-board (which it does very well). Apart from the task-board, it provides so much more functionality that in some ways it comes close to becoming a replacement for Team Explorer (although it runs on top of Team-Explorer and so you do need to have TeamExplorer installed on your machine).

The task-board not only allows you to review the different states in which your work-items are in, but also allows you to change state by dragging and dropping them in a different state swim-lane. You can add work-items, review work-items, filter them and a whole lot more. Another cool feature is the Project Dashboard, a constantly updating screen of project information – a great way to get a quick overview of the project.

The WIM is a very cool project and you should take a look at the video that Telerik has made demoing all its features. (video)

tb Task-board sample.

Telerik Work Item Manager

Monitor text files in real-time

As a developer I use text files all the time to write out information to log application events. These logs become extremely valuable when I am trying to debug a problem (especially while an app is running in production).

Typically I used to load up the file in NotePad++, which would provide me with a notification everytime the log file changed, allowing me to decide if NotePad++ should reload the document. (TextPad also provides similar functionality).

Today, I came across an awesome tool called BareTail, that allows me to monitor log files in real-time. BareTail automatically updates itself as the log file changes and it can display lines that were added or deleted. BareTail almost feels like a video player that is streaming what is happening to your log file.

Apparently, the origin of the name Bare-Tail is from the UNIX tool that provides similar capability called “tail” (run as tail –f).

It is definitely a tool that you should add to your dev-tools box.

BareTail -

NotePad++ -

Happy Diwali – Diwali song from the Office!

Thursday, October 15, 2009

TFS – Forcing refresh of reports

The data that is used by TFS in its reports is stored in a SQL Analysis Services database. This data is stored in an OLAP cube. The cube is not update in real-time, which is the reason that TFS sometimes shows out of date information in its reports.

Fortunately, there is a way to request* for the cube to be updated. To do this, you need to log in to your TFS server. Open a browser and browse to:

Select the “Run” method, then click the Invoke button.

You should receive a XML response with the value true in it. A value of true signals that the OLAP update process has been started. Now to determine when the update process has completed, you can invoke the “GetWarehouseStatus” method. This will return the values “Idle” or “Processing Olap”. The ware-house is refreshed once you get the Idle response status. 

*The reason that I said “request” is that in practice I have found that Sql Server Analysis Services does not always begun refreshing the cube and will always return the Idle response. In this case – go home and come back the next day – by when it should update the cube.

Monday, October 12, 2009

jQuery UI Dialog and Positioning

Sometimes the default and automatic center positioning of a jQuery dialog upon opening does not work.

jQuery("#dialogDiv").dialog({ height: 'auto', modal: true, width: 400, autoOpen: false, position: 'center' });

I found the following code works to position the jQuery UI dialog in the center of the screen:

var x = document.body.clientWidth / 2;
var y = document.body.clientHeight / 2;
var dlg = jQuery("#dialogDiv");
dlg.dialog('option', 'position', [x, y]); //dlg.dialog('option', 'position', 'center');

Sunday, October 11, 2009

Two DNN issues I had to fight with this weekend

Had to really weird DotNetNuke (DNN) issues to work through that had me working most of this weekend.

The first one had to do with what manifested as a javascript error - “this.container.parentnode is null or not an object”

The issue turned out to be because I was using the JQuery javascript library. The library provides the $ macro as a shortcut to jQuery. But DNN already uses the $ macro, which causes issues. Fortunately, the fix is simple. Call the following method in a script block in the head of the document:


This stops jQuery from trying to use the $ alias. Which means that you cannot use the $ alias to select DOM objects. Instead, whereever you use $ to work with JQuery, you need to directly reference the library using “jQuery”.

eg: $(document) becomes jQuery(document)

The second issue had to do with ViewState and a user control that was loaded using LoadControl

In other words, the user-control was being loaded dynamically using the LoadControl module. For the most part, the control was working. What was not working was the ListBox was not keeping its SelectedItem value, after I had selected an item in the ListBox and then clicked a button that caused a post-back.

After running around in many many circles, the thought that I have is that its because the ViewState is not working correctly. (The user-control works fine if I directly reference the user-control in a aspx page. The problem only occurs when the user-control is added dynamically using the LoadControl module).

The way I worked around this issue is that whenever I added items to the ListBox, I stored the items to the Session object. I then over-rode the OnInit method, and use the items in the Session object to load into the ListBox. The reason that I think this solution works is that the view-state is not working correctly and so I am giving the control a helping hand by filling it with the values that it should have after a post-back. All other events occur after the OnInit method has been called, allowing the SelectedItem to be correctly set.

Saturday, October 10, 2009

Messaging & Positioning 101

From Camberely Bates presentation at the New Tech group (video):

For who: Identify your customer

Does what: what problem does it solve or how does it improve my life/job

Unlike: what differentiates you from the competition

iPhone – Applications start and shut down immediately

Since last night, my iPhone had started acting weirdly. Every 3rd party application that I attempted to use would start up and immediately shut down. The only applications that worked were the ones that came with the iPhone originally.

Most posts that I read prescribed that I wipe out the iPhone and reinstall everything – that would take too long and didnt sound like the way I wanted to spend my weekend. So on a whim I tried a couple of steps and voila! all applications began working again.

Here are those steps:

1. Perform a complete shut-down of the iPhone. (Hold the round button on the face and the power button on the top of the iPhone for a few seconds and the iPhone will perform a hard shut down).

2. Start up the iPhone.

3. Now install some new app that you dont have already on your iPhone.

4. Try opening one of the apps that wasnt working. (Cross your fingers, cause if it doesn't work – then you might be out of luck and might have to do a complete reinstall). If the app does work – then rejoice – you just kicked the iPhone back into behaving correctly.

Friday, October 09, 2009

JQuery – Attribute Filters

JQuery attribute filters make it easy to select and modify particular attributes in your HTML DOM.

For example: if you wanted to hide all links in a page, here is what you need to do


But what if you need to hide only some of the links on your page?

Maybe the one that links to “”


Maybe all the ones that have google in the href….


(the key to above filter is the “*” – which matches anywhere in the attribute’s value)

Maybe all the ones that end with org


(the key to the above filter is the “$” – which matches to the end of the attribute’s value)

Maybe all the ones that begin with http://doc


(here the the key is the “^” character – which matches only to the beginning of the attribute’s value)

Here are important points to remember:

  1. The filters are case sensitive. (I dont think there is a way to make them case-insensitive)
  2. Unlike regular RegEx expressions – you do not need to escape characters (such as “/” and “&”)
  3. This was true as of JQuery 1.3.2

Tuesday, October 06, 2009

How things work - Shaazam

I always wondered how Shaazam worked (the app that automagically identifies songs). And today, I came across this document by one of the Shaazam creators that explains how it works:

The basic idea is that it uses a songs spectrogram (a graph of time on the x axis, frequency on the y axis) to generate a signature for each song. Samples uploaded from phones are converted to a spectrogram and compared against a database of pre-generated spectrograms to figure out information about the songs.

Fluent Tutorials

4 useful tutorials on using Fluent for NHibernate.

A fluent interface to NHibernate - Part 1
A fluent interface to NHibernate - Part 2 - Value Objects
A fluent interface to NHibernate - Part 3 - Mapping Relations
A fluent interface to NHibernate - Part 4 – Configuration

Also, remember, Fluent is an interface to NHibernate, so you can do anything you could do with NHibernate. A good example is performing queries. I searched all over for information on how to perform queries using Fluent for NHibernate and didnt find any. And then when it dawned on me that I could use NHibernate, I found a ton of resources.

Here is one from NHibernate’s documentation pages:

Virtual Sphere – Cool interface to computers

PhotoSketch – A cool way to create new images from existing ones

PhotoSketch: Internet Image Montage from tao chen on Vimeo.

Read more about PhotoSketch on ZDNet -

Get the source code from:

Monday, October 05, 2009

Fluent NHibernate – Connecting to SQLServer

Here is the code to create a ISessionFactory that can be used to work with a SqlServer database

ISessionFactory sessionFactory = Fluently.Configure()
.Database( MsSqlConfiguration.MsSql2008
.ConnectionString(m => m.Server(@".\SqlExpress")
.Mappings(m =>
.ExposeConfiguration((Configuration config) => new SchemaExport(config).Create(false,true))
return sessionFactory;

The code uses a local SqlExpress database called “Fluent_Test”. The mappings are stored in the same assembly as the method in which the above code is placed.

Saturday, October 03, 2009

Do you know what Google Wave is?

A quick video on what Google Wave is…..

Windows 7 Tips

  1. Command prompt here
    Up until Windows Vista, we had to download a registry hack to get the option to start a command prompt from Windows Explorer.
    In Windows 7, just press shift and then right click on a folder and presto, you get the option “Open Command Window Here”.
  2. Presentation Mode
    Press Windows Key + “P”. You get a window that allows you to quickly choose where the video from your computer is directed:
  3. Windows + “Home”: Minimize all windows except the currently active one
  4. Start apps as administrator (“Run as Administrator”): Click on the application icon with Shift and Ctrl buttons pressed.
  5. Use Sticky Notes: Search for Sticky Notes
  6. Windows Power Shell - Batch scripts evolved: If you need to write complex batch scripts, check out Windows Power Shell. And while you are at it, try out the Windows PowerShell ISE (Integrated Scripting Environment) as the editor for creating and editing these scripts. (Search for PowerShell ISE)

Get more advanced tips from: