Tuesday, January 29, 2008

Quote of the Day

I love the little ads that Gmail has ontop of your inbox. Usually there is a lot of garbage but sometimes there is something that is golden like this one:

Quote of the Day - Margaret Thatcher - "I am extraordinarily patient, provided I get my own way in the end."

This describes me so well in one sentance...

I just love it

Calculating a Random Date in C#

I found myself needing to calculate a random date & time btw a given minimum and maximum date. I ended up creating the following function which appears to work very nicely.

internal DateTime CalcDate(DateTime minDate, DateTime maxDate)
{

//This assumes _rand is a private variable of type System.Random. It calculates a new timespan
//that can be added to the minimum date which will create a new date btw
//the min & max
TimeSpan timeSpan = maxDate - minDate;
TimeSpan randomSpan = new TimeSpan((long)(timeSpan.Ticks * _rand.NextDouble()));
return minDate+randomSpan;

}


One thing I ran into which I was not aware of was that while you can add DateTime & a Timespan as such: DateTime + TimeSpan, the reverse is not true, you cannot add TimeSpan+DateTime.

This to makes no sense particulary since addition is supposed to be commuatitive.

Friday, January 25, 2008

Neat Tool - Colorize your code

Found this neat tool today CodeHtmler, courteous of Tomas. It allows you to take plain text code, and converts it to HTML applying standard colors to it. Preety neat tool that can help you liven up your code when posting it online.