Saturday, April 25, 2009

Simple, But Very Clever

I was reading some articles on PCWorld (see my last post to find out why) and came upon an interesting link in one of the comments.  The link took me to SuperFiller.  It's a simple service which helps solve a problem I have all the time.  Have you ever put together an order on Amazon where all the items qualify for free shipping, but the total is a bit shy of the required 25 dollars?  Well, as the front page of the site shows, you can ask SuperFiller what items are available on Amazon for $1.47, or whatever amount you need.  It's simple and probably wasn't very hard to code, but someone had to think of it.

p.s. I'm guessing they make a small amount of money on each purchase through Amazon Associates referral fees.

Friday, April 24, 2009

I'm Quoted in PCWorld!

Juan Carlos Perez from IDG News Service (the parent company of PCWorld) contacted me today to ask if I'd be interested in speaking with him about the Amazon Web Services offerings. He explained that he was writing an article on the subject and wanted to hear how customers felt about it. We had a nice chat late this morning. I let him know that I've experimented with EC2 and S3, but haven't done any production work with either. I made sure to plug the Boston Scalability User Group (of which I've been a member since the first meeting) and mentioned that we'd already had Mike Culver of Amazon as a speaker.

The result was an article which appeared in PCWorld: " Eyes CIOs With Its AWS Cloud IT Services". My quotes were pretty clunky (apparently me thinks and me writes more gooder than me talks :) ), but I think readers will at least be able to figure out what I meant.

the article also appears in InfoWorld and ComputerWorld Norway

Another Update: I contacted the reporter about the clunkiness of my quotes.  He said that since the article had already been published, he would have to run any changes by his editors and it would effectively be treated as a retraction/correction.  That's obviously overkill, so I guess I'll just have to live it and follow his suggestion for next time: ask the author to run quotes by me before the article is filed.

Sunday, April 5, 2009

Blogger Causing Problems for SyntaxHighlighter

I kept noticing blog entries with beautifully rendered source code snippets and finally clicked the blue question mark in the upper left of one and discovered that they were using Alex Gorbatchev's SyntaxHighlighter JavaScript library. For my last post, I followed the instructions in the Usage Guide, using the hosted version since I can't upload JS files to Blogger, at least as far as I know. If you look at my post, you'll notice that I have two 1 line Groovy snippets and one 5 line Java snippet. The 1 liners were no problem, but when I first tried to display the 5 lines of Java it showed up as just one line with visible <br> tags where the line breaks should have been. It turns out that when I pasted the code into Blogger's post editor, even though it was in HTML source mode, it inserted <br> tags for the line breaks even though they were showing up inside of a <pre> tag. It turns out that there are two solutions to the problem. I'll explain the better one first, although I didn't find out about it until trying the other one.

When I asked Google for help, it led me to a page talking about how to use SyntaxHighlighter with Blogger. The post itself didn't contain any new information for me, but the comments were useful. "Robje" had apparently experienced exactly the same problem as me. "Debiprasad" then asked, "What is your settings for 'Convert line breaks' set to? In my case, if I set it to 'Yes', it's inserting <br/> into codes defined under <pre> tag." Ah ha! I looked on the "Formatting" subtab under the "Settings" tab in the Blogger control panel and discovered that mine was set to "Yes". Ack! What an annoying default! With it set to "No", it seems to fix the problem.

In case that doesn't work for you, Google also brought me to a page on what must been the old home for SyntaxHighlighter. Once again, the gold was in the comments. "fahd.shariff" mentioned that if you use the post editor in Blogger in Draft, this isn't a problem. As I said earlier, I gave this a try before finding the preferable solution and it worked for me so it's a reasonable solution to fall back on.

Succinctly Groovy

I was reading a post on displaying Google Visualization charts in Grails on mrhaki's blog and noticed something interesting. In his code, mrhaki wanted to get a handle on the newest (most recently modified) file in a directory. His approach was to list the files in the directory, sort them (in ascending order), reverse that, and then get the zeroth item:
def xmlFile = dir.listFiles().sort{ file -> file.lastModified() }.reverse()[0]
It's a nice example of how you can express a somewhat complex flow in a single line of Groovy. Still, it seemed like overkill to me and another reader who failed to identify him or herself. That reader linked to the Groovy Collections page and suggested using a Comparator that sorted the list in descending order to start with, but didn't include a code snippet. I liked the fact that this approach avoids the extra work to reverse the sorted list, but I wasn't sure it would be possible to express it so compactly and it still seemed more complicated than necessary. I looked over the Collections page and was reminded of the min(Closure) and max(Closure) methods available on Groovy's enhanced collections. So, rather than sorting the list of files, you can just ask for the max as determined by last modified date:
def xmlFile = dir.listFiles().max{ it.lastModified() }
Nice and simple, eh? Ignoring the overhead of imports and class/method declaration, neither of which are necessary with the Groovy snippet, here's the most compact way I know of expressing this using the Java standard libraries:
File xmlFile = Collections.max(Arrays.asList(dir.listFiles()), new Comparator<File>() {
  public int compare(File file1, File file2) {
    return (int)(file1.lastModified() - file2.lastModified());
I'm glad Groovy's out there!