Thursday, July 31, 2008

Backwards Computability Only Goes In One Direction

This is just a little story of a stupid moment by me. This morning I was working on some stuff for a client when a weird error popped up. The error occurred after I had updated the client library side of a client server pair to be at version 2; the server, however, is at version 1.3.

Version 2 is supposed to be backwards compatible with 1.3 but it wasn't working. It seemed crazy; I even asked someone else to look at it and he too was stumped. From the subject line you have probably already identified the problem. The Server side is backward compatible with clients running 1.3. There is no way the server, which was running 1.3, could be forward compatible with 2.0 clients. Duh.

I'm such a moron sometimes.

Wednesday, July 30, 2008

OT: And Now For Something Completely Different

As hard as it might be to believe I do a lot of other things beyond writing and hacking at code. I play a ton of sports but, to stay true to my geek stereotype I also read a lot. I mostly read speculative fiction (fantasy, not much sci-fi), military fiction, and a bunch of non-fiction and now I've started my own blog to talk about those books.

Recently I also started reading a bunch of review blogs and, truth be told, I think the idea is pretty cool. I've written a few book reviews on my personal blog before but I had never really thought of devoting a blog to just the books I read. Now, however, I have decided to give it a go. I've not had much experience writing reviews while not spoiling the books so at the moment my reviews are definitely far more about my impression of the book as opposed to what takes place in it. Hopefully that format will be interesting to some readers.

If you happen to visit my new review blog please drop a comment and let me know if the review is useful or not. Either way any suggestions or advice on what might make the reviews better would be great.

Here are some of the other sites I've been visiting/reading:
A Dribble of Ink
Graeme's Fantasy Book Review
Pat's Fantasy Hotlist
The Wertzone

And now, back to your regularly scheduled programming of programming trivia..

Last.Fm and Amazon Together Again

A while ago I debuted my first Yahoo Pipe; last.fm @ Amazon that basically took your listening list and did a lookup on amazon. The idea being that anyone who could consume an rss feed could then monetize their listening habits.

The cool thing about Yahoo pipes are that you can mashup a bunch of different services into one nifty data source. That trick, I have discovered, is that not all of the data sources you use necessarily remain the same. A case in point is the Amazon Web Service which, at some point between now and Feb 07 has changed to requiring a new token to identify the developer who is making the service call and a different sort by enumeration.

Needless to say my pipe had broken. Fear not however as I managed to get it back up and working in almost no time. I did learn a valuable lesson in doing so though - don't accidentally delete your pipe! Fortunately, a bunch of people had cloned my old broken pipe so I was able to "re-clone" it so to speak and get it going again without much trouble.

Finally, if you don't really care how the pipe works but would like to use it you can use the following URL as the feed URL you want to display in your blog (or feed reader) http://pipes.yahoo.com/pipes/7d20665c0dc0240fd18516ec360efe21/run?_render=rss

You can append the following to the URL if you want to provide your own last.fm username and/or amazon associate ID;

&username=YOURUSERNAME&associateTag=YOURASSOCIATEID

Just replace YOURUSERNAME with your last.fm username and YOURASSOCIATEID with your amazon associate id. Just note if you publish this feed anywhere and you don't provide an associateTag value it will use mine by default; granted, I wouldn't mind that - but I figured i should tell you.

Flotr - a Javascript Plotting Library

Flotr is a very cool, very slick, Javascript plotting library built on Prototype. The examples show some pretty impressive functionality and some really nice looking graphs.

It supersedes the older Plotr library which is now deprecated.

Thursday, July 17, 2008

Blackberry - Dial a Letter

When you are using your blackberry you may come across a situation where you want to type a phone number that consists of letters.

For example. Google offers a free information service at 1 800 GOOG 411 (those are oh's and not zeros).

With the blackberry keyboard layout it is hard to remember what keys to press to dial GOOG - this cool trick will help you get past that.

When dialing the number you can type 1800 just like normal, but then, when you want to type GOOG hold the alt key down and press the letter you want to dial. The blackberry will then send the correct tone for that letter (G = 4, O = 6) when the call is actually placed.

You're blackberry screen will show the number being dialed as 1800GOOG411

Hope this helps some of you at some point!

C# : Parsing a URL for its Component Parts

I recently had need to break a URL down to it's component pieces so that I could use just those parts that I needed at different times. My initial approach to solving this problem was to Google for a built in solution to parsing URLs in C# but I couldn't find one. So then I feel back to a RegEx pattern. .Net in general has some nice regex features (including being able to name groups) and so this is the RegEx I came up with (after looking at some others that already existed):


private static Regex pattern = new Regex("(?<protocol>http(s)?|ftp)://(?<server>([A-Za-z0-9-]+\\.)*(?<basedomain>[A-Za-z0-9-]+\\.[A-Za-z0-9]+))+((:)?(?<port>[0-9]+)?(/?)(?<path>(?<dir>[A-Za-z0-9\\._\\-]+)(/){0,1}[A-Za-z0-9.-/]*)){0,1}");


However, that RegEx has a problem where it won't get the full Port number if the port is immediately followed by a query like so:
http://my.domain.com:8000?arg1=this&arg2=that

Instead of returning the port of 8000 the regex ends up with the port of 8. That sucks. Fortunately, I know someone else who I could ask about it and he pointed me at the useful built in C# library : System.Uri.

Why this library didn't pop up in my Google queries I don't know but, let me tell you, it does pretty much everything I need. However, I do have one minor quibble. The protocol portion of the URL is parsed out and identified by Scheme.

Now, with a string based representation of a URL I can break it down quickly using the System.URI class. Lets say you want to get the port:


string url = "http://my.domain.com:8000?arg1=this&arg2=that";
System.Uri uri = new System.Uri(url);

// get the port
int port = uri.Port;

// get the host name (my.domain.com)
string host = uri.Host;

// get the protocol
string protocol = uri.Scheme;

// get everything before the query:
string cleanURL = uri.Scheme + "://" + uri.GetComponents(UriComponents.HostAndPort, UriFormat.UriEscaped);


As you can imagine there is actually a lot you can do. If you don't think you can find a bit from the URL check out that uri.GetComponents method - the UriComponents enumeration has a bunch of options you can dig into!