my recent reads..

Atomic Accidents: A History of Nuclear Meltdowns and Disasters; From the Ozark Mountains to Fukushima
Power Sources and Supplies: World Class Designs
Red Storm Rising
Locked On
Analog Circuits Cookbook
The Teeth Of The Tiger
Sharpe's Gold
Without Remorse
Practical Oscillator Handbook
Red Rabbit

Sunday, February 24, 2008

Quick NLB Catalogue Lookups

Postscript: I've given up all ambitions of hacking NLB now that I have discovered Bookjetty - a bookshelf site with library integration. Check it out!

OK, so this post won't mean diddly unless you live in Singapore, or have a local library using the CARLweb system.

But say you are browsing one of the book retailers on the web - like amazon - and you want to know if the book is available in your local library?

Here's a little trick to help you find that out in one-click (not patented;-). It is inspired by some posts over at The Box Factory.

Below is a link that you save to your bookmarks (Firefox)/favorites (IE). Once saved, when you are on a book page at amazon etc, just select the bookmark/favorite and it will pop-up a window to Singapore's National Library Board catalogue system and try and find the book in the library for you.
NLB Book Lookup <-- Bookmark/Favorite this!

Simple steps: How to Use It

  1. Right-click on the link above, and select Bookmark This Link.. (Firefox) or Add to Favorites.. (IE)

  2. Go thru the steps to save the link. you may get a warning about "javascript:" links not being recognised. Ignore/proceed .. trust me!

  3. Check you Bookmarks/Favourites menu - should now find NLB Book Lookup in the list.

  4. Navigate over to a book retailer and find a book (try the Ruby Cookbook (O'Reilly) at Amazon for example)

  5. While viewing the book page, select NLB Book Lookup from your Bookmarks/Favorites menu

  6. A new window will open to display the NLB Library Catalogue record (if there is one)

Grumpy Stuff - But Looking Forward

The NLB is still using CARLweb, which is an ancient product from TLC.

Once of the really nasty features of this system is that it uses session tracking in the URL query string of your request. Not only does this prevent deep-linking (so you can't easily email a catalogue link to a friend for example), it makes the catalogue un-indexable by web search engines like google.

It also means that the Bookmark/Favorite link I gave you above has to go in the front-door, and creates a new session each request. So unfortunately that means that if you use this a few times in quick succession, you may get a maximum sessions exceeded error. Sorry, for now you'll just have to close the windows and wait a while for sessions to expire.

Yes, CARLweb sux. It truely belongs to an earlier era of computing!

The good news: I've heard whispers that the NLB have a project running to upgrade their catalogue search facilities. Hopefully we'll soon have a much better service to use. My top wishes:
  • Support for deep-linking. No user/session-related information in URLs.

  • A nice robots.txt that allows the search engines to fully index the catalogue

  • Flexible RSS feeds - as well as the usual "latest acquisitions" etc, a flexible and published approach to parameterising the feed e.g. by library location, by subject and any other search criteria. Or another way to express this would be "get any search result as RSS"

  • Getting ambitious now ... a published Web Service/REST API

  • A mashup developer's guide - encourage people in Singapore to exploit the NLB catalogue! A competition even?

Explaining Regular Expressions

Unless you get to work with regular expressions everyday, the details can easily blur. You remember enough to know when a regex could be useful, but not enough to write it without reaching for a reference manual.

There are a few tools out there to help you write and understand regular expressions, including some IDEs that can provide assistance (like Komodo).

Sometimes you just want a quick explanation of a regular expression you might have seen in some code. The YAPE::Regex::Explain perl module is one tool that helps you do just that. Turning the module into a simple command-line tool is a simple one-liner:
#!/usr/bin/perl -w
print YAPE::Regex::Explain->new($ARGV[0])->explain;
I've also turned it into a simple CGI utility for those times when my regex memory fails me. You can use it here: regexplainr (sorry, you may find that site offline but here's the source code).

In a previous post, On Parsing CSV and other Delimited/Quoted Formats, I used the following regular expression to parse a whitespace-delimited string:
"([^"]+?)"\s?|([^\s]+)\s?|\s
Regexplainr produces the following commentary:
The regular expression:

(?-imsx:"([^"]+?)"\s?|([^\s]+)\s?|\s)

matches as follows:

NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
" '"'

----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
[^"]+? any character except: '"' (1 or more
times (matching the least amount
possible))
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
" '"'
----------------------------------------------------------------------
\s? whitespace (\n, \r, \t, \f, and " ")
(optional (matching the most amount
possible))
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
( group and capture to \2:
----------------------------------------------------------------------
[^\s]+ any character except: whitespace (\n,
\r, \t, \f, and " ") (1 or more times
(matching the most amount possible))
----------------------------------------------------------------------
) end of \2
----------------------------------------------------------------------
\s? whitespace (\n, \r, \t, \f, and " ")
(optional (matching the most amount
possible))
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
(Permalink to this regexplanation)

Book tip: (thanks to Tony) O'Reilly's Mastering Regular Expressions. Available on google books, and also from Amazon.

Tuesday, February 12, 2008

Popflying the Oracle Community

Back last year I got all excited about Yahoo Pipes ( Web 2.0 Wake-up Call for BPEL? ) and its graphical approach to building mashups. In fact I still use a Pipes mashup as my mega-aggregated Oracle newsfeed.

Now I've discovered a new toy - Microsoft Popfly - and finally a reason to install Silverlight! I remember popfly getting mentioned in Bex Huff's roundup of mashup tools last year, but at the time it was still in restricted beta.

Popfly's still in beta, but now open to one and all. Put aside your biases for a minute and go play ... if you are like me, it will blow your mind. It may not be the final word in mashup tools, but it sure opens your mind to what should be possible.

Here's a little mashup I created 5 minutes up the learning curve. It's a cute display of the latest photos posted to the Oracle Community site:


Postscript: yes, you do need Silverlight installed for this to work of course. Silverlight is available for "all major browsers running on the Mac OS or Windows". If you are not prompted automatically for the Silverlight install, visit the Silverlight site.

Monday, February 11, 2008

Supporting Singapore's bid to host the Youth Olympic Games 2010


I just discovered the online campaign to support Singapore’s bid for the Youth Olympic Games 2010. It would be truely great to see the event held here, and Signapore's certainly got the location, facilities, environment and culture to do a great job.

And to be fair, better chances than ever hosting the full Olympic Games!

So I've registered my support, and you'll see the logo flying on my blog from now on;-)

If you want to support the bid on your blog, just register here.

Postscript 21-Feb-2008: Singapore Wins!
Support Singapore YOG 2010

Sunday, February 10, 2008

On Parsing CSV and other Delimited/Quoted Formats

Parsing delimited text that may have quoted elements is a perennial requirement. Quick-and-dirty parses can be achieved with regular expressions, but for more flexible and encapsulated parsing I've been checking out the opencsv java library. Hat tip to Jakub Pawlowski for highlighting the library on his blog

A Regular Expression Approach
Just recently I released and blogged about a JDeveloper Filter Add-in, and it contains a class called ExecShell [API, source] which needs to know how to break a command line into its component arguments. The command line is of course space-delimited, but may use quotes to group an argument with embedded spaces (so a simple split on spaces won't do).

The salient code below uses the REGEX to chop theCmdLine String into theCmdArray Vector of arguments:
Vector<String> theCmdArray = new Vector<String>(0);
String REGEX = "\"([^\"]+?)\"\\s?|([^\\s]+)\\s?|\\s";
Pattern p = Pattern.compile(REGEX);
Matcher m = p.matcher(theCmdLine);
while (m.find())
{
theCmdArray.add( m.group().trim() );
}

The regular expression bears a little explaining, and is inspired by this example. Here's how it breaks down:

\"([^\"]+?)\"\\s?
Matches a group within double-quotes. Group is a lazy match on one or more characters except double-quote. Optionally followed by some whitespace
|([^\\s]+)\\s?or Matches a group delimited by whitespace, optionally followed by some whitespace
|\\sDiscards a pure whitespace match

In this case, we are using whitespace as the delimiter (appropriate for command lines). The regex can be adapted for other delimiters by replacing \\s with the delimiter. For example, to handle a comma-separated format:
String REGEX = "\"([^\"]+?)\",?|([^,]+),?|,";

Using OpenCSV
The same space-delimited parsing requirement can be met with a couple of lines and the opencsv library:
CSVReader reader = new CSVReader(new StringReader(theCmdArray), ' ');
String[] s = reader.readNext();

Simple, yet currently not so robust. Since we define the delimiter to be a single space (over-ridding the default comma), other whitespace characters (like a tab) will not be recognised. Further, repeated spaces will not be coalesced, but will each be treated as the delimiter for a new element.

Internally, CSVReader parses the input character-by-character and so adapting to handle repeated delimiters as one would be reasonably straight-forward.

Saturday, February 09, 2008

The Right Way To Do Wrong - a good read for security buffs


The Right Way To Do Wrong - An Exposé of Successful Criminals is a very old book, published in 1906. I was intrigued since it was written by Harry Houdini, and I hadn't realised he was also an author.

Houdini's motive for writing the book is to warn off the righteous by educating them in all forms of devious frauds and scams, and to cause those less well intentioned to give pause before taking up a life of crime.

Reading the book over 100 years after publication, I am amazed - but perhaps on reflection not surprised - that Houdini manages to describe in great detail just about every Internet-related scam in existence (allowing of course for a transposition of technology)!

When he talks of Begging Letter Swindles, think Nigerian Letter or "419" Fraud. For Tricks of Bunco Men, see Advance Fee Scheme. The ease in which Impersonation/Identity Fraud was practiced in a pre-IT age... and just about every other gambit you can find on the FBI Common Fraud Schemes site.

If you are into IT Security, I think you'd enjoy reading this and mulling over the relevance to your day-to-day work. It is salutary to realise there is nothing new in the Evil that Men do, just new ways of doing it!

I listened to The Right Way To Do Wrong in audio from LibriVox. It is also available in print from Amazon.

Monday, February 04, 2008

iTunes and DRM - Destroy Real Music

Ignatius Low gets nostalgic over music in it's physical form in an article for The Straits Times today (I still want a CD I can hold - Feb 3, 2008 - article is only available to online archive subscribers. ST hasn't quite caught up with the NYT yet!).
ABOUT a month ago, I made my first purchase from the Apple iTunes Store. It was a tedious and deliberate process, given that the iTunes Store hasn't been launched in Singapore yet, but it had to be done..

He goes on to question what would be lost if the world does move wholesale to digital downloads .. nostaligic memories of browsing for music with friends in the local record shop .. the personal stories forever tied to each CD or LP on your shelf.

Travelling and the Real Music Store Experience
Thankfully, we haven't totally lost the music store experience yet, although it is dominated by the major chains like HMV. I hope we never lose it. It would deprive me of one of the most enjoyable travel activities - whenever in a new city, I always try to make time for a few hours at a local music store to browse and buy. It is a great way to get a lock on the local music culture and discover some amazing artists.

DRM - The Worst Idea Ever Foistered on the Music Industry
There is a more insidious side to the whole digital download approach to purchasing music. Its called DRM - Digital Rights Management (or Destroy Real Music if you prefer). Still in use for most music on iTunes, DRM restricts your use to iTunes and iPod, and you only get 5 chances to register with another computer (like if you re-install or upgrade). Apple of course are not exactly forthright in telling you all this, prefering to regale you with all the benefits of digital downloads.

To make a LOTR analogy, its as if DRM is the poison holding Théodred under the spell of the wicked Wormtongue (read RIAA).

When I look at my record collection, I see the albums I inherited from my parents - even grandparents - and remember the thrill of exploring and learning to appreciate all this old and unusual music. I was the new generation rediscovering the musical gems of my elders, and I think a critical step towards musical maturity. It is how I found a place in my collection for Les Paul & Mary Ford, Duke Ellington and Fats Domino along side Iron Maiden, Madonna and Regurgitator.

If DRM and digital downloads become the way of the future, then this is one formative experience I will be unable to bequeath to any grandchildren I may be lucky enough to have.

The Dawn of a DRM-free Golden Age?
Thankfully, DRM seems to be on the way out - at least for music if not movies for the time being. And anyone who really cares about music should add their strength to kill it good and proper as soon as possible. EMI were perhaps the first major label to signal the trend, and break away from Wormtongue's spell.

The EMI move significantly bolstered Amazon's move on itunes with their DRM-free MP3 store (although in a perverse turn of logic, I can order physical CDs from Amazon yet because I live in Singapore I still cannot purchase their mp3 download versions. Go figure!)

Amazon's move was likely no insignificant factor in Apple now moving to dump DRM in their new iTunes Plus service (probably more correctly called iTunes Minus). Aple are still extremely coy in telling their users what's really going on (try searching for DRM on the iTunes site). I think it is scandalous how little information is provided to iTunes users about the DRM restrictions that are still applied to the majority of songs you can purchase on iTunes.

To put it simply: beware!
  • When you purchase music on iTunes, it is still DRM-locked, unless you are clearly given the iTunes Plus purchase option.
  • If you buy DRM-locked music on iTunes which is later made available unlocked in iTunes Plus, you can upgrade but you will have to pay for the privilege of getting you music purchases switched over (currently 40c per song or 30% of the album price)

Personally, I plan to stick to purchasing CDs, especially with so many available today at a nice price (like S$11.95 and up for recent chart albums). When amazon finally make the mp3 store available to me, I'll probably use that for the odd purchase (especially for individual tracks).

But iTunes? Sorry Apple. I love your iPods, but your support for DRM leaves such a bad taste that even now that you are reforming I will run a mile before willingly purchasing from your store.