The writings of Peter Stuifzand

Archive for September 2008

All music players suck, all in different ways. The music player that I created sucks too. A lot actually, but that's to be expected.

The work of three days is now available to the public in some kind of alpha release. The player is called Fiddle and is available in my Git repository. But please take a look at the website that I created for it. It contains a lot of good information about downloading and running Fiddle.

I even created a logo.

The main feature that made me want to write a new music player, was Smart playlists. All music players contain a version of so called Smart playlists, but they all kind of suck. In Fiddle you can create simple scripts or queries that will find all music files that match in then play them in the order that you specified.

For example:

name Rated music in order
play_count not match /^0$/
rate match /^\d+$/
order rate desc

This will play all music which has been played before and has a rating, from good to bad. There are many playlists like this that could be used.

Fiddle is a work in progress and I could use help from people who would like to create a better music player. So if you want to help, please send an email to the mailing list.

I created a Greasemonkey script that will show a hovering statusbar when hovering over a link. It looks like this:

Hovering statusbar

Use at your own risk! This script comes with no warranty. You have been warned.

Install the script: Hovering statusbar Greasemonkey userscript

The last few days I've been using jQuery to write some REST based javascript and HTML. While I was doing that I needed a function that looked like getJSON, that did a POST instead of a GET. The difference is that I send a bit of JSON and receive a bit of JSON, instead of sending form-like data. So I created the following bit of code:

$.postJSON = function (url, data, callback) {
    $.ajax({
        'url': url,
        'type': 'post',
        'processData': false,
        'data': JSON.stringify(data),
        contentType: 'application/json',
        success: callback,
    });
};

If you know jQuery a bit, you will know that this sends an Ajax request to url. Later when I used this code to do a POST a followed by a GET, I didn't receive the thing that I wanted: a Javascript object. I did however get a string that looked like one. That confused me for a bit. Then I remembered a FAQ or a weblog post about another implementation of postJSON, that was written like this.

$.postJSON = function(url, data, callback) {
    jQuery.post( url, data, callback, "json") ;
};

It seemed my problems where solved. When I clicked around my website, everything had stopped working. I checked what this code was doing and it did something different than what I expected. It doesn't send the data variable as JSON, but as application/x-form-encoded.

First the problem was that the code didn't parse the return value. Then the problem became that the code didn't encode the arguments as JSON. When I found the problem the change was easy: change the callback to parse the return value. The final code became this:

$.postJSON = function (url, data, callback) {
    $.ajax({
        'url': url,
        'type': 'post',
        'processData': false,
        'data': JSON.stringify(data),
        contentType: 'application/json',
        success: function (data) { callback(JSON.parse(data)); },
    });
};

The current problem is that this method has a different interface than the normal postJSON. So I have to choose a different name.

submit to reddit

View archived entries