Posts from March 2010

Frontal - a new approach to triggering Javascript behaviour

My friend Carl has just released a really interesting Javascript library called Frontal. I've had a night to sleep on it and thought I'd share my thoughts.

The key problem Frontal addresses is 'some Javascript needs to be run only on some pages'. There are a few different approaches to this:

Per-page scripts

The first approach is to have lots of Javascripts that only apply for the current page, and insert them in the HEAD of the document:

Tether to iPhone with Ubuntu 9.10 Karmic Koala

I just did a fresh Ubuntu Karmic reinstall after an ill-conceived upgrade to a Lucid Alpha, so I had to try and retrace my fairly muddled steps in configuring iPhone tethering.

Because I had a fair idea what I was doing this time it was pretty easy, so I figured I'd best document the steps for the next unfortunate soul trying to do the same. I'd also be interested to hear if the same steps apply to Lucid once it's out of Beta.

iPhone tethering

The first thing to do is get tethering enabled by your operator. For some reason O2 can only enable it overnight so make sure you get it well before you'll need it. Once it's enabled, you'll find your phone has a new option under Settings->General->Network->Internet Tethering. Make sure you turn it on in here and then forget about it - it's only enabled for devices that are paired over Bluetooth or USB so there's not much of a security worry.

The next step is to get the Ubuntu side sorted. The best bet is to install the Bluetooth Manager widget Blueman, which will replace your existing Bluetooth widget. Blueman is much better than the default simple widget, but unfortunately either the way the iPhone exposes its network access point is non-standard or it's a bit advanced because the older version of Blueman in the Ubuntu Karmic sources is not capable of connecting - you'll need to install a newer version from Blueman directly.

The best way of doing this is to add the Blueman PPA and install it from them via apt:


$ sudo add-apt-repository ppa:blueman/ppa
$ sudo apt-get upgrade
$ sudo apt-get install blueman

I found after doing this the old bluetooth widget was hanging around, but restarting X fixed that.

Clarifying Javascript-PHP communication using JSON-RPC

I think of myself first and foremost as a PHP developer but serious sites are getting more and more JS-heavy as time goes on so it gets harder (and less pragmatic) to try and avoid dealing with JSPHP communication of some sort.

I'm a big advocate of RESTful design so tend to end up attempting to write scripts that do lots of GETs and POSTs (as appropriate) and parsing out whatever custom response format I've decided JSON requests will return. It feels good - like I'm sticking to my principles and 'doing it right' but it's a long painful slog that can feel like self-flagellation at times.

It's also slow and hard to prototype - it's hard to argue in favour of some abstract design idea when it's making you take forever to generate simple tasks . Sometimes when I feel lazy what I really want is a way of calling my PHP objects directly from the JS and not worrying about what's happening in the underlying HTTP, and that's what JSON-RPC provides.

In this blog I'll be showing some simple examples of JSON-RPC in action but first let's look at the pros and cons.