CommuterJoy » Logbook

« logbook home

Posted by mattc at Dec 28, 06 05:05 AM

Posted by mattc at Dec 27, 06 07:20 PM ... Comments (6)

I've released some code I wrote over the summer in the hope I can find someone with a few hours to help me finish it off. As in, someone who writes better Perl than me.

I've called the project betfairfree and, as the description on Google's subversion hosting says, it's an 'interface to the free version of BetFair's Sports Exchange API', and to liberally quote from BetFair themselves ...

"With the Exchange API, you can communicate directly with the Betfair database in XML format via a SOAP interface. By using the Exchange API, your application can provide a custom interface, functionality and specialized operations not otherwise afforded by the web interface."

The code is in a usable state, but certainly not finished, and suffice to say I don't make my living writing Perl.

The main things on the todo list are a) to get a complete coverage of the free API (probably only implements 60% of it at the moment), b) as always, the code deserves a second pass with some areas needing refactoring, and c) some decent examples of what one might do with it, which will of course be the fun part.

It's not going to get finished in a hurry, by me at least, but I'll try to transfer my own notes in to the various areas of the now-public project wiki, issues etc.

The API is described in SOAP, which I've not used before, but I enjoyed working with strongly typed XML documents, and Matt Sergeant's XML::Xpath module was great for removing the headache from working with the heavily nested nodes and multiple namespaces that seem to come hand in hand with SOAP.

So if you have any interest, do download the project files and drop me a line if you have anything to contribute.

Posted by mattc at Dec 26, 06 10:39 PM ... Comments (0)

The CitiGroup building at Canary Wharf on a cold December evening.

Posted by mattc at Dec 22, 06 05:05 AM

Posted by mattc at Dec 21, 06 05:05 AM

Posted by mattc at Dec 20, 06 05:05 AM

Posted by mattc at Dec 18, 06 05:05 AM

Posted by mattc at Dec 16, 06 05:05 AM

Posted by mattc at Dec 15, 06 05:05 AM

Posted by mattc at Dec 14, 06 05:05 AM

Posted by mattc at Dec 13, 06 04:36 PM ... Comments (0)

I was just about to write a regular expression, when suddenly ...

I stumbled on the fact that upon feeding dates formatted as RFC 822 (as commonly found in RSS 2.0) in to a newly instantiated Javascript Date object it just handles it. No ifs or buts, it just works. I didn't expect that.

 var foo = 'Fri, 04 Apr 2003 05:04:39 GMT';
 var bar = new Date( foo );
 var woo = bar.getYear()  // woo holds '2003'

How very helpful. This means I could combine some getElementsByTagName construct with Date to give me an array of feed items by date without too much fuss ...

 var foo = new Array();
 // where 'o' is the response from some xmlHTTP request
 var rss = o.responseXML.getElementsByTagName("item");  
 for ( var j = 0; j < rss.length; j++ ) {
    foo.push( new Date( rss[j].getElementsByTagName("pubDate")[0].textContent ) );
     }

But wait. Simon and Mark point out that RSS has many dates and times.

So I wonder how JavaScript handles these?

 // load each date type in to foo
 var foo = new Array('2003-03-21T16:28:40', '2003-04-03T07:45:57-08:00', 'Fri, 04 Apr 2003 05:04:39 GMT', 'Fri, 28 Mar 2003 05:18:59 -0800', '1049379042.0', '2003-03-21T16:28:40', '2003-01-17T13:03:00+00:00', '2003-03-27T19:41:49-06:00' );
 // iterate foo and write the year to the screen
 for ( var i = 0; i < foo.length; i++ ) {
   var bar = new Date( foo[i] );
   // print output, attempt to call getFullYear
   document.write( foo[i] + " - " + bar.getFullYear() + "\n" );
   }

In Opera 9, almost perfectly ...

 2003-03-21T16:28:40 - 2003
 2003-04-03T07:45:57-08:00 - 2003
 Fri, 04 Apr 2003 05:04:39 GMT - 2003 
 Fri, 28 Mar 2003 05:18:59 -0800 - 2003
 1049379042.0 - NaN  // bah!
 2003-03-21T16:28:40 - 2003
 2003-01-17T13:03:00+00:00 - 2003
 2003-03-27T19:41:49-06:00 - 2003

The only error is the obscure '1049379042.0', which I assume is a reference to the number of seconds passed since midnight 1970. I'm not sure who is using that in their pubDate fields !?

IE 6, Firefox 1.5 & Safari 2.0.4 do much worse, only managing to parse and return valid Date objects from 2 out of the 7 dates.

 2003-03-21T16:28:40 - NaN 
 2003-04-03T07:45:57-08:00 - NaN
 Fri, 04 Apr 2003 05:04:39 GMT - 2003
 Fri, 28 Mar 2003 05:18:59 -0800 - 2003
 1049379042 - NaN
 2003-03-21T16:28:40 - NaN
 2003-01-17T13:03:00+00:00 - NaN
 2003-03-27T19:41:49-06:00 - NaN

So, to recap, Opera's Date object supports ISO 8601 date parsing upon construction, everything else doesn't.

I find the ECMA standard terse at the best of times, it's unclear whether it's meant to be doing this or not.

I also see MochiKit provides extensions for this sort of thing via it's DateTime library.

Posted by mattc at Dec 13, 06 02:59 PM ... Comments (0)

Travailler moins, produire plus. (The less you work, the more you produce)

French paradox, quoted in How to be Idle, by Tom Hodgkinson.

Posted by mattc at Dec 13, 06 05:05 AM

Posted by mattc at Dec 12, 06 05:05 AM

Posted by mattc at Dec 11, 06 10:18 PM ... Comments (0)

A few trees on the top of Leith Hill at dusk.

The first one is taken through a pair of sunglasses looking directly at the fading sun.




Posted by mattc at Dec 9, 06 05:05 AM

Posted by mattc at Dec 7, 06 05:05 AM

Posted by mattc at Dec 6, 06 09:56 PM ... Comments (0)

Found. In the darker corners of my hard drive, a list of modules I studied at Portsmouth, so I'm posting them here for safe keeping.

Year 1

Year 2

Year 3

The final year project investigated the different means of structuring large repositories of information for ease of access and navigation (by the user) with particular attention to the evolution and success of hypertext based systems (eg. memex, hypercard, the web etc.)

Posted by mattc at Dec 6, 06 05:05 AM

Posted by mattc at Dec 2, 06 05:05 AM

Posted by mattc at Dec 1, 06 05:05 AM

random bookmark
link summary month October 2009 (1)
September 2009 (14)
August 2009 (16)
July 2009 (21)
June 2009 (24)
May 2009 (16)
April 2009 (2)
March 2009 (22)
February 2009 (11)
January 2009 (11)
December 2008 (9)
November 2008 (16)
October 2008 (18)
September 2008 (11)
August 2008 (12)
July 2008 (20)
June 2008 (15)
May 2008 (27)
April 2008 (9)
March 2008 (10)
February 2008 (8)
January 2008 (8)
December 2007 (12)
November 2007 (10)
October 2007 (10)
September 2007 (6)
August 2007 (13)
July 2007 (8)
June 2007 (10)
May 2007 (12)
April 2007 (5)
March 2007 (12)
February 2007 (13)
January 2007 (22)
December 2006 (21)
November 2006 (28)
August 2006 (1)
category code (15)
food (4)
notes (4)
photo (18)
project (2)
quote (12)
sketch (13)
soup (10)
travel (2)