Category Archives: Fun

Byzantime – a historical snippet for every minute of the day

oldbookA couple of days ago, a colleague remarked how his wife was able to relate the time in the morning to a year in the life of the Byzantine Empire….

“0811 [pause]. Year of the Bulgarian massacre of the troops of Nicephorus I”

I needed a little project, and so Byzantime was born – for every minute of the day, it will display a historical event by interpreting the time as a year.

Under the hood

While it’s fun in itself, what I really wanted to play with was Silex. This is a microframework based on Symfony components, aimed at making single-file apps like this concise and testable.

We’ve been using Symfony at Alexander Street Press for over a year, and I’m impressed at how it’s really helped us raise our game when it comes to quality of engineering. But when you need to make something smaller, it feels like overkill.

So, I gave Silex a try. I’m pretty impressed with the results. It’s certainly concise – to give you an idea, the page needs to request some JSON containing events for the current hour. Here’s how the routing for that is handled using Silex:

$app->get('/event/{year}', function (Silex\Application $app, $year) {


    $events=$app['historian']->getEvents($start, $end);

    return $app->json($events);

})->assert('year', '\d+');

Only 6 lines of code, but a lot is going on here. Firstly, we’re defining the route for our AJAX request defined as /event/yyyy, where yyyy is the year we’re interested in. This parameter is passed to our handler closure..

The next two lines just do a little arithmetic.

Then we reference $app[‘historian’], which obtains a previously configured service class from the Pimple dependancy injection container provided by $app. Much like a Symfony service, if we never use it, it won’t be created. Having got the service, I obtain an array of events.

We want to return that data as JSON, and Silex provides a hander helper to do just that.

Finally, you’ll see theres a chained call to assert our year parameter is numeric. If it’s not, the closure would not be executed.

Look at that – it look far longer to describe in English!


I recently dusted off the original code to stick up on github. While PHP gets a fairly bad rap, when I compare old code like that to something taking advantage of current technologies like Silex, Composer and Doctrine, it makes me smile. This is a good time to be working with PHP!

Comments on Byzantime are welcome, I think I’ll probably use it as the basis for further experiments…

The Monty Hall Problem

goatI was a bit bored a few weekends ago, and happened to read a
BBC News article about the Monty Hall Problem.

Suppose you’re on a game show, and you’re given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what’s behind the doors, opens another door, say No. 3, which has a goat. He then says to you, “Do you want to pick door No. 2?” Is it to your advantage to switch your choice?

I’ve come across the problem before, but thought it might be fun to make a page which let you play the game and kept score. So here it is:

This started out as a little toy project to allow me to explore some areas of Symfony and Doctrine I’ve not used much. But, I’ve decided to get into the habit of polishing these little experiments and releasing them.

Give it a try!

Chicken Phal, anyone?

Many years ago, a friend and I attempted to eat a Chicken Phal. Ordered from an excellent establishment in Newcastle upon Tyne, the proprietor urged us not to eat it.

But eat it we did.

The following day I vowed never to attempt anything quite so daft.

Time heals all wounds though, and some 17 years later I’ve been talked into repeating the episode for Comic Relief. It’ll be a lot of fun to watch the pain, so please sponsor me if you can.

Click the link, you can sponsor me online and it only takes a minute or two.

Edit: we had to abort doing this on comic relief night due to my co-conspirator attending a funeral. The mayhem will take place in late April now…