Monday, April 19, 2010

.Net Color To HTML Color And Back

Color translation between the .Net color type and the #rrggbb color type is made really easy using the System.Drawing.ColorTranslator class. The calling code itself is simple:

    public string ColorToHtmlStr(System.Drawing.Color c)
    {
        return System.Drawing.ColorTranslator.ToHtml(c);
    }

    public System.Drawing.Color HtmlStrToColor(string HtmlColor)
    {
        try
        {
            return System.Drawing.ColorTranslator.FromHtml(HtmlColor);
        }
        catch
        {
            //Return a default if the HTML color string parameter is invalid
            //The value of the default could be passed as a second parameter.
            return System.Drawing.Color.Black;
        }
    }

Wednesday, April 14, 2010

Cryptographically Strong Random Number Generation With C#

In C# it's sometimes handy to be able to generate usable random numbers whether its for collision avoidance, security, generating realistic dummy data or just testing inputs. The problem is that using the built in .Net Random class several times in quick succession, although fast, will give you identical results for a given unit of execution time (assuming you are seeding with a time value, which most people seem to do).

Tuesday, April 6, 2010

14 TV Shows That Jumped the Shark | Real TV Addict

Nice post at realtvaddict.com that lists 14 TV Shows That Jumped the Shark.

Pity about SVU, always liked that show but it needs to either end or get new writers. C'est la vie.