Use C#’s regular expression library to Convert TimeSpan and DateTime to and from strings. (Named capturing groups!)

Well that title is a mouthful.  Long story short, as an exercise in regular expressions I wrote a utility class to convert strings to TimeSpans and DateTimes in C#.  This made great usage of named capturing groups.  (The download to the source code is at the bottom of this post.)

Here is the DateTime regular expression.  Note that when I new the regular expression object, I set whitespace and casing ignoring.
image

Named capturing groups allows code like this:
image

In the end, the utility class allows code like this:
image

fun!  Download all of the code here.

Have any suggestions about the code?  Any neat C# features I should have used?  Comment below!

OkCupid wut?

Per a friend’s prodding, I recently got on free dating site OkCupid.  Even though I am already seeing someone, it’s still fun to answer the questions and find my real-life friends.  The site is full of surprises, like this email that I received today.

(I deleted my personal info from the email. No stalkers for me!)
OkCupid good-looking wut 

This left me thinking, “Well that’s nice wait wut?”  Take from this what you will…

Kind of related, OkCupid does a bunch of cool (geekish) data crunching and publishes the findings on their OkTrends blog..

Another novel (and silly) use for Roomie

I’ve been working (rather obsessively) on Roomie for the past week.  In specific, I have rewritten the XML-based protocol that allows the desktop client to communicate with the web service.  (Say “hi” to it here.)  The new library (which I call WebCommunicator) is sooo much easier to use than my old one, but still has all the nifty (and important) encryption and anti-hacking features.  I will eventually publish the protocol as an independent library.  (Give me a bit to use it more and work out all the kinks.)

But enough technical talk.  Lets get to serious business.  Here I have a little RoomieScript that I wrote, just as a proof of concept.

<RoomieScript>
  <ZWave.PowerOff DeviceName="Coffee Pot" />
  <Core.Loop>
    <ZWave.WaitForChange DeviceName="Coffee Pot" PollInterval="5 Seconds" />
    <ZWave.PowerOff DeviceName="Coffee Pot" />
    <RoomieBot.TextDavid Text="No coffee!" />
  </Core.Loop>
</RoomieScript>

Continue reading