Archive for July, 2008

Run for cover 2.0

The Run for cover widget has been abandoned for ages, as I only supported my Last.Fm Records plugin for Wordpress. Two things make me publish a new version of this Wordpress widget: disappointment from people stuck with PHP4 and therefore unable to use the new version of Last.Fm Records — and the joy of parsing XML with of jQuery…

Run For Cover shows the cds you listened to recently, as you can see in the sidebar. All data is real time, so the widget shows you if you are listening to a track at this moment. It’s still a rough version, especially the javascript, but it works on my test sites and I know people are looking for such a widget.

The widget needs jQuery, luckily this comes with recent versions of Wordpress. If you get an javascript error about jQuery, you could check the readme.txt .

You can download Run for cover 2.0 here.

Update: the javascript seems to fail under some versions of Internet Explorer. First thing when I’m back home after the holidays.

No project complete without a todo list

  1. better error checking
  2. show a message when last.fm is unavailable or when data was not correctly loaded
  3. use nice jQuery effects when displaying the cd covers
  4. auto update function after x minutes

Hope you like it — I’d like to read what you think in the comments.

New version and project plans

Just committed version 1.4.1 of Last.Fm Records to Wordpress, to fix a couple of issues. The biggest one is the one that Rose pointed out, and I hadn’t seen yet. Thanks, Rose! She saw that if you selected ‘get more images if necessary’, the plugin didn’t display the correct images.

I also removed the commented out code that was displayed on the settings page.

The feedback has been extremely encouraging to work on this plugin. For Last.Fm Records the todo list is the first thing I’m planning to do.

The stand alone version is next. As it is already PHP5, I suspect there’ll be less disappointed people. Don’t think I’ll start on this one before I’m off on a three week holiday.

And a special note for anyone stuck on PHP4: LFM used to be called Run For Cover. I’m using that name to work on a widget that uses jQuery to parse the recent tracks list from Last.Fm. It’s still very beta, but you can follow development on that one by downloading the development version. If you make sure jQuery is loaded (see readme.txt for instructions) and activate the widget, it will display your recent tracks.

Version 1.4 of Last.Fm Records released

This was a big one for me — implementing the new last.fm API. I have submitted my changes to wordpress.org, so you should see a message on the plugins page that the new version is available.

To make this happen before my holidays, I had to disable some things from the previous version:

  • uploading images (already uploaded images will remain in your cache directory)
  • selecting a style

Please let me know how this new version works for you in the comments! I’m especially interested in what you think of the new option ‘get more images if necessary’.

If any bugs show up I’ll try to fix them before this or another sundown.

Last.Fm API

Last.fm has made available their new API two weeks ago — and it’s a big step forward. I did apply for a preview to update my Wordpress plugin Last.Fm Records before the API hit the streets, but alas. So the last few evenings I’ve written version 1.4.

Version 1.3 had a really ugly parseHTML function to parse the HTML pages requested on last.fm. Now that the API returns relatively clean XML, the first thing I did was to update the XML parsing to the functionality available in PHP5, which means I no longer support PHP4. All the Amazon and Musicbrainz requests have been replaced by requests to the new API. Great news is that almost all relevant feeds in the new API include urls for cd covers: only user.getWeeklyAlbumChart (cds you listened to last week) is lacking those: why?

Thanks to the new API the plugin is much faster, finds more images than the previous version, and is now in beta. If you want to test drive it, let me know in the comments. I’ll release this new version after testing it thoroughly. I’ll be listening to songs with single quotes and ampersands in the title!

Oh, and yes, the request (by a human being) for a fallback option has been implemented: when the period you set in the options returns not enough cds, the plugin requests more info from longer ago.

Programming Brain Teaser

Dustin Diaz told a programmer’s riddle — impossible to leave these things alone. So I wrote a solution. One thing bugs me: the itch that this could be done much, much easier.

var arr = ['a', 'b', 'c', 'c', 'd','e', 'e',
              'e', 'e', 'e', 'f', 'e', 'f', 'e',
              'f', 'a', 'a', 'a', 'f', 'f', 'f'];
var bingo = false;
// first two are never in a span
var result = arr[0] + ' ' + arr[1];
// old fashioned for to start at 3rd element
for (var i = 2; i < arr.length; i++) {
  // is this the third in a row?
  if ((arr[i] == arr[i-1]) && (arr[i] == arr[i-2])) {
    // start bookending them if that hasn't already been done
    if (!bingo) {
      result += ' <span>';
      bingo = true;
    }
  } else {
    if (bingo) {
      result += '</span>';
      bingo = false;
    }
  }
  result += ' ' + arr[i];
}

// close last one?
if (bingo) {
  result += '</span>';
}

// remove space after opening span tag
result = result.replace(/<span> /g, '<span>');
alert(result);