Yet another happy WordPress user…

January 27th, 2009 Comments off

Since I am currently in the buying fase for a self-owned server on a colocation, I thought it to be the perfect time to move over to a self-hosted blog. Since one of my friends and colleagues, Wouter Goedvriend, is a very happy WordPress user, I too gave it a try Yet another happy WordPress user... icon smile

Hope to meet you a lot on my new blog! Keep up your good work!

Categories: wordpress

Logging duration with System.Diagnostics.StopWatch instead of using DateTime.Now

January 9th, 2009 2 comments

Still using two DateTime.Now calls to determine the duration of a certain call execution, like beneath?

DateTime start = DateTime.Now;
DoSomeCall();
double secondsToLog = (DateTime.Now - start).TotalSeconds;

This is not at all necessary: using the StopWatch class. The StopWatch class is more efficient than any other solution provided or created in .NET since it uses low-level API calls and supports a high-resolution performance counter (when there is hardware and software support).

Stopwatch watch = new Stopwatch();
watch.Start();
DoSomeCall();
watch.Stop();
double secondsToLog = watch.Elapsed.TotalSeconds;

Windows Explorer from Visual Studio

January 9th, 2009 2 comments

Windows Explorer is one of my favorites, especially when coding (in Visual Studio). I often navigate to the file, folder, or project I’m currently working on. Clicking “Windows Explorer” in the Tools menu would be helpful if we could manage to get it there… and ‘yes we can!’.

How?
Go to Tools -> External Tools… -> Add.

In the screen you are presented with, enter:

Title: Windows Explorer
Command: explorer.exe
Arguments: /select,”$(ItemPath)”
Leave Initial directoy blank

Click OK. When you click Tools -> Windows Explorer, the explorer will open with the selection on the current file you are editing in Visual Studio.

Visual Studio 2005 and the vaporized Immediate Window

December 19th, 2008 Comments off
Today I reinstalled my development virtual machine. For a couple of ‘legacy’ software packages I must have Visual Studio 2005 installed as well. Debugging one of those software packages mentioned above, I wanted to ‘hack my runtime’ using the Immediate Window. It wasn’t there!
Since I always have the Immediate Window activated, I cannot remember the shortcut for it (Ctrl+Alt+I Visual Studio 2005 and the vaporized Immediate Window icon smile ). Looking for the menu item to activate it (yes, of course, in the Debug menu) it appeared to be gone. Sadly this is a known bug. The only way to get it back into the menu is using the Tools menu, click Customize, select the Commands tab, choose for Debug commands and drag Immediate onto the toolbar.
For some kind of overview:
Visual Studio 2005 and the vaporized Immediate Window The disappeared immediate window
I simply assume nobody likes it either Visual Studio 2005 and the vaporized Immediate Window icon smile

Dutch social security number check

November 20th, 2008 Comments off

For a Dutch customer I currently work for, I dealed with an incorrect social security number check (in Dutch: elfproef voor BSN’s/burgerservicenummers). After checking out the Internet for the correct definition of Dutch social security numbers (e.g. Burgerservicenummer – Wikipedia), I created the next check in C#:

string cleanBsnNr = bsnNr.Trim().Replace(".", "");

// A BSN consists of 9 characters ...
if(cleanBsnNr.Length != 9) return false;

// ... all being numeric and not resulting in a 0 when converted to a number ...
long l;
if(!long.TryParse(cleanBsnNr, out l)) return false;
else if(l == 0) return false;

// ... the number must be validatable to the so-called 11-proof ...
long total = 0;
for(int i = 1; i <= 9; i++)
{
    // 11-proof voor BSN's: (9*A + 8*B + 7*C + 6*D + 5*E + 4*F + 3*G + 2*H + (-1*I)) % 11 == 0
    int number = Convert.ToInt32(cleanBsnNr[i - 1].ToString());
    int multiplier = 10 - i;
    if(i == 9) multiplier = -1 * multiplier;

    total += number * multiplier;
}

// ... not result in a 0 when dividing by 11 ...
if(total == 0) return false;

// ... and not have a modulo when dividing by 11.
return total % 11 == 0;

Good luck when you should build one for yourself. Checking your own built check can be done using this website with generated BSN’s (or your own, of course) by Menno Wilmans.