Monthly Archives: March 2006

PHP5 Iterators

I’m late to the PHP5 party. When it was released I kicked the tyres, wrote a few sample scripts, but lacked the time and resources to deploy it properly.

But as I’m about to start a large new project, it’s time to bite the bullet!

I’m playing around with Xapian, which is a C++ search library with a nice object oriented interface, but the PHP bindings for it exposed it as a series of functions, so I set about writing a wrapper to mimic the “real” API.

I noticed several classes implemented an iterator, so I thought it would be an opportunity to try and use the Iterator interface, and found a great article on PHP5 Iterators over at Scatterism.

Within a few minutes, I was able to turn a slightly ugly Xapian loop into a nice foreach – behold!

Before

$mseti = MSet_begin($matches);
$end=MSet_end($matches);
while (! MSetIterator_equals($mseti, $end)) {
        $doc=MSetIterator_get_document($mseti);
	$percent=MSetIterator_get_percent($mseti);
	$docdata=Document_get_data($doc);
	MSetIterator_next($mseti);
}

And after!

$mseti=$matches->begin();
foreach($mseti as $doc){
	$percent=$mseti->get_percent();
	$docdata=$doc->get_data();
}

Proof that iterators really do wash whiter and shift the stains inferior patterns leave behind :)

RESTful images

Thought I’d play around and make a WordPress plugin to show a selected Geograph image, and form the beginnings of a REST style API for Geograph.

First thing was to provide a way to obtain picture metadata – this was pretty straightforward – requesting a URL like this

Returns an XML result like this

<geograph>
<status state=”ok”/>
<title>From Bygrave to Baldock</title>
<gridref>TL2435</gridref>
<user profile=”http://www.geograph.org.uk/profile.php?u=2″>Paul Dixon</user>
<img src=”http://www.geograph.org.uk/photos/04/02/040212_f4e3079a.jpg” width=”480″ height=”640″/>
</geograph>

I knocked up a plugin which maintained a list of “interesting” picture ids, and if it has been displaying one for more than 24hrs, requests the metadata for the next image in the queue, pulls in the image and resizes it suit this layout, and generates a cached HTML fragment for display

I could do with adding some extra metadata to the result, as well making new REST style APIs for user profiles, grid squares etc. We already have an API for bulk data retrieval which needs a key, but these simpler APIs might enable more little gizmos like this one to be produced.

Producing Open Source Software

Producing Open Source Software is a great looking book which you can read online. I’ve only had time to skim a few chapters but it does resonate with my experiences developing Geograph. While some of it can be applied to commercial teams, the majority of it is about dealing with the unique elements of open projects.

There’s a few things we could learn for Geograph, such as keeping all discussions public unless there is a real need for them to be private. There’s a lot of interesting history lost in email that we should be preserving for any future developers.

Abbey 0 – NatWest 1

Because the Ordnance Survey are sponsoring Geograph out of their 2005 budget, they need to spend it this month!

Anticipating this, we set the ball rolling on opening a bank account for Geograph many weeks ago with Abbey. Every week I called for an update, only be told “you’ll get your account number within a week Mr Dixon”. Last week they told me something new – could be *two* weeks, plus another five days to send my information pack out. They couldn’t possibly tell me my account number over the phone. Oh no. Data Protection Act you see. Data Protection my arse.

So the Abbey have the lost the opportunity of some positive PR from Geograph. They may offer free banking but if you want an account within 6 weeks I’d steer clear.

I’ve now tried NatWest (current slogan: Another Way) and the local branch in Hitchin couldn’t have been more helpful, figuring out exactly how they could get the account open asap. I picked up the forms last wednesday and did a full circuit of the M25 that night to get a signature from Geograph co-developer Barry Hunter. Took the forms back to the branch on Thursday.

It’s now Monday and I have the account details! Well done NatWest! There is Another Way!

Third time lucky

I’ve tried this blogging thing twice before, and the trick is to have some focus or purpose. Last time around it was just for logging daft and interesting links that I didn’t need to bookmark, but might want someday. Del.icio.us soon did a better job of that for me.

So what will I write about?

  • The Geograph Project – takes up a lot of spare time
  • Geocaching - the only activity which gets me outside at the moment
  • PHP and C++ software development, as that’s what I spend my days doing
  • I’ll undoubtedly throw in a few daft links too :)

OK! Let’s go!