Finding your way home with Clojure

Learning a new technology is much more fun when you actually have a mission. So I decided to make a little web app that can show the departure times of streetcars in Toronto.

This is possible because the City of Toronto has made the NextBus API available as part of its Open Data initiative, which provides info about routes, stop locations and arrival time predictions.

You can see the end result in the screenshot below, or try the app yourself on my test server. (If it is down, clone the code from Github, it is very simple to run the web app)

Mozilla Toronto Transit Board

Many thanks to Sean Martell for his superhero CSS skills to make it look so good.

Like my previous Clojure experiment, this app also uses the Angular.js framework on the client side and Ring, Compojure, Chesire and clj-http on the server side.

There is a good chunk of XML parsing in the app using clj-xpath and I also implemented a very basic geo-spatial database that currently has a naive find-objects function, but is plenty fast. (Less than a millisecond to find stops in a database with more than 10000 entries. Yay for JVM speed.)

The app has two modes of operation:

  1. Location based - where it will ask your browser for your current location and then show departure times for streetcars and buses within a 250 meter radius. This is the default. See Demo (Only finds stops if you are in Toronto)
  2. Preconfigured stops - this uses a list of stops that you can provide. The current app has two, one for where I work and one for where I sometimes play. You can change the list of stops in index.js and reference a configuration by putting it’s name in the location hash. See Demo

The project is open source and you can find the code at https://github.com/st3fan/departures-board

Most of my professional and personal work is Open Source. You can find many projects at github.com/st3fan - feel free to leave a bug report or open a feature request.