2011-09-05

Extensions...

Here's a little extension on Object in C#

public static bool EqualsAny<T>(this T obj, params T[] compareTo)
{
  for (int i = compareTo.Length - 1; i >= 0; --i)
  {
    if (obj.Equals(compareTo[i]))
    {
      return true;
    }
  }

  return false;
}
If the original code would have looked something like this before:
int nowHour = DateTime.Now.Hour;

if (nowHour.Equals(10) ||
    nowHour.Equals(12) ||
    nowHour.Equals(15) ||
    nowHour.Equals(17) ||
    nowHour.Equals(19) ||
    nowHour.Equals(23))
{
  //Happy hour!
}
the after code would look like this:
if (DateTime.Now.Hour.EqualsAny(10, 12, 15, 17, 19, 23))
{
  //Happy hour!
}

2011-09-04

Lazy mans guide to code syntax highlighting on Blogger

Having just moved some old blog entries to a brand new blogger.com blog from Wordpress I was looking for an easy way to publish highlighted code in my posts.

There are several different tools freely available such as SyntaxHighlighter, highlight.js and Prettify which I decided on using.