The Circus is in Town

20 Oct 2011

Following a couple of late caffeinated nights, I am pleased to announce that Untyped’s latest project, Bigtop, is finally set for beta release!

Bigtop is a collection of libraries for web developers. Included in the first beta release are:

  • Bigtop Routes - a library for creating type-safe bidirectional mappings between URLs and Scala code;
  • Bigtop Core - a library for generating and manipulating URLs and hyperlinks in a functional style.

Routes uses the HList-based approach to bidirectional pattern matching that I presented at Scala Lift-Off London 2011. There are versions of the library for use with Lift, Scalatra, and plain old Java servlets.

Check the Bigtop web site for a getting started guide, API documentation, and links to the code and Maven repository.

Reading, Writing, and the REST

10 Oct 2011

I’ve just finished preparing the slides for my talk at Scala Lift-Off London 2011 next week. The title of the talk is A Route to the Three ‘R’s: Reading, Writing, and the REST. Here’s the abstract:

The mappings between URLs and code form an integral part of any web application. Many web frameworks help map from URLs to code, but the reverse mapping is often neglected, leaving developers to construct URLs via haphazard string manipulation. Furthermore, many frameworks do not match URLs in a type-safe manner.

Scala provides all the tools we need to address this problem in a more comprehensive manner. In this talk we will walk through the creation of Bigtop Routes, a bidirectional mapping library that is both type-safe and developer-friendly. We will pay particular attention to the ways in which Scala language features, such as flexible syntax, implicit conversions, and a touch of type-level programming, help to simplify the task at hand.

The slides and code samples are all available from my Github page. With any luck, the nice folks at Skills Matter will record the talk and post a video. If/when they do, I'll post the link here.

Update: Skills Matter have posted a video of the talk on their web site!

Friday fun with Scala syntax

27 May 2011

It’s been a while since I’ve posted, so I thought I’d steal one of Noel's ideas and throw up two fun Scala programs for your amusement.

Scala has a pretty flexible syntax (although not as flexible as Racket's, of course) that makes it popular amongst proponents of DSLs. Not all DSLs have to be serious, however, as I’m about to prove.

First up is Noel’s original concept - proof of his love for DSLs, expressed in purest code:

    class A(num: Int) {
      def Scala = "It's s" + ("o" * num) + " much fun!"

    object I {
      def <(num: Int) = new A(num)

    I <3 Scala
    // ==> "It's sooo much fun!"

Second is a simpler work that I call “The Startled Lolcat”:

    object O { def o = "What has been seen, cannot be unseen." }

    // ==> "What has been seen, cannot be unseen."

Less CSS compilation for SBT

06 Apr 2011

Continuing my line of SBT plugins, I just put together a tiny plugin for compiling Less CSS files.

This is very similar to the Closure Compiler plugin I knocked together last month. Instructions on use are in the README on the Github page.

Javascript compilation for SBT

06 Mar 2011

Over the weekend I knocked up a little SBT plugin to wrap all of my Javascript resources in my Lift projects and deploy them as one big minified file. Read on to find out how it works, then grab yourself a copy and take it for a spin.

The plugin scans your webapps directory (where all of your static HTML, Javascript, and CSS files live) and looks for files with the extensions .jsm or .jsmanifest. These files, called Javascript Manifests, describe lists of Javascript sources that should be combined into a single file. For example:

    # You can specify remote files using URLs...
    # ...and local files using regular paths
    #    (relative to the location of the manifest):
    # Blank lines and bash-style comments are also supported

Manifest compilation happens in two phases: first, the plugin downloads and caches any remote scripts specified using URLs. Second, it feeds all of the sources (remote and local) into Google’s Closure Compiler, which concatenates them and minifies everything (and provides excellent services like static type checking to boot). The output from the compiler is a .js file with the same base name and relative path as the original manifest.

There’s not a lot more to it than that. The plugin hooks into SBT’s standard compile and package phases, so your Javascript gets rebuilt automatically alongside your Scala code. If this sounds useful to you, please feel free to grab a copy and take it for a spin. Full details are available in the README on Github.

I should point out that there are other useful SBT plugins that do a similar job. For example, I plagiarised extensively from Jon Hoffman’s YUI Compressor plugin and Luke Amdor’s Coffee Script plugin when writing my code. These two particular examples don’t do file combination, though, and that was an important feature for my specific use case.

Smooth Scrolling for Mobile Safari

23 Jan 2011

I recently wrote a jQuery plugin to do some smooth scrolling on the iPad, and I thought I’d share the code with everyone.

The effect you get is very similar to the iOS home screen. The user touches the screen and drags to scroll. Releasing the screen causes it to spring to the most appropriate page based upon the last dragging position and speed.

Gurus of front end development tell us that pretty much the only way to get smooth transitions on the iPad is to use 3D CSS transforms. After experimenting with jQuery animations and 2D CSS transforms, I pretty much concur: jQuery animations yield one or two frames per second, and 2D CSS transforms aren’t much better. 3D CSS transforms, on the other hand, are hardware accelerated and smooth as silk.

You can get the code from this Gist on Github (contributions and enhancements welcome). Use it with the following HTML:

    <div id="viewport">
        <div>First page</div>
        <div>Second page</div>
        <div>Third page</div>

and the following Javascript:


There’s a demo of it in action here. A couple of notes:

  • Because this hooks into touch gesture events and CSS3 3D transforms, it’ll pretty much only work on iDevices and possibly other Webkit-based tablets.

  • It works horizontally and vertically, but I’d recommend only using it horizontally in a regular web page because it interferes with Safari’s natural screen bounce.

    I had the benefit of a working on an offline brochure where the web page never scrolls naturally. In this environment the plugin really shines. If you are interested in doing something similar, take a look at the iPad app Delivery Site, which lets you customise various things like this.

  • There are a couple of options you can tweak to affect things like dead-zones before a drag will trigger a page transition. See the top of the source code for details.

  • When the first 3D transform is added to a page, Mobile Safari seems to transparently install an OpenGL panel to handle the effects. This causes a rendering glitch that’s just faintly visible if you’re paying attention. The plugin works around this by setting an identity transform on the scroll component on page load. Webkit is presumably frugal about 3D-ification for a reason, so you may find your web pages take more memory and CPU resources with this plugin active than without.

  • Really large (read “many-page, full-screen”) scroll panes can be very heavy on the browser. This is presumably due to the overhead of creating a texture buffer to 3D accelerate the transitions. I’ve managed five-page full-screen scrolling transitions without problems, but your mileage may vary.

Update (1st March 2011): This code is now listed on

Box & What?!

15 Jan 2011

Forget what they said in Contact - mathematics is not the fundamental language of the Universe. When aliens try to solve big problems, they do it just like us - by scrawling diagrams on the back of napkins.