Author: David

  • MOTOCAL: Personalised motor racing calendars

    MOTOCAL: Personalised motor racing calendars

    I like just about any kind of motor sport. If it has wheels and an engine then I’m probably interested in watching it drive round in circles for a couple of hours. But there are a few race series I follow closely and try to watch on TV whenever I can: Formula One, MotoGP, Superbike.

    Wouldn’t it be good, I thought, if I could subscribe to a single calendar feed that showed all the races I was interested in (and none of the ones I wasn’t).

    So I built MOTOCAL.

    I’ve put all the hard work into collecting all the qualifying and race times so you don’t have to. Just click on each race series you want in your calendar and it will generate a URL that you can stick into your calendar application (Google, Apple, Outlook) and you will get a synchronised calendar that is automatically kept up to date.

    You can currently subscribe to any and all of the following:

    It’s pretty easy to add more calendars so leave a comment if you would like to see any other series.

  • Garmin Communicator WordPress Plugin

    Garmin Communicator WordPress Plugin

    I run the ridemap.org website which is a collection of motorbike routes and I wanted a way for people to download the routes to their GPS devices. Originally I was just going to provide a downloadable GPX file but then I found that Garmin have a browser plugin that allows data to be transferred between your Garmin GPS device and your computer.

    After getting it working on my website I decided to wrap it up in a WordPress plugin to make it easier to integrate in posts.

    You can get the code from GitHub.

    To use the plugin you will need to get a free Garmin site key from the Garmin Developer website. Then create a custom WordPress field called ‘gpx’ with your GPX data and insert the [[gpxconnect]] shortcode into your post. This will add a button to allow users to download the GPX data directly to their Garmin device.

  • TextMate for IntelliJ users

    TextMate for IntelliJ users

    I use IntelliJ IDEA. I also use TextMate. The fact that I spend most of my day in IntelliJ means I’m used to IntelliJ’s keyboard mapping which happens to be slightly different from TextMate’s.

    The biggest difference I found was with the Home and End keys and the Delete Line mapping. So here’s how to make TextMate work more like IntelliJ.

    Change Home and End keys

    From this old blog post:
    Create the custom KeyBindings folder (if it doesn’t already exist):

    mkdir ~/Library/KeyBindings

    Create a key bindings file called DefaultKeyBinding.dict in this directory with the following content:

    {
        /* home */
        "\UF729"  = "moveToBeginningOfLine:";
        "$\UF729" = "moveToBeginningOfLineAndModifySelection:";
    
        /* end */
        "\UF72B"  = "moveToEndOfLine:";
        "$\UF72B" = "moveToEndOfLineAndModifySelection:";
    
        /* page up/down */
        "\UF72C"  = "pageUp:";
        "\UF72D"  = "pageDown:";
    }

    Change Delete Line mapping

    Go to Bundles > Bundle Editor > Show Bundle Editor.
    In text bundle, change Delete Line from CTRL+K to CMD+DELETE.
    In the text bundle, Delete to Beginning of Line macro, click the X to remove the same binding.

    Change Duplicate Line mapping

    While you are there you might also want to change the Duplicate Line / Selection mapping to CMD+D

  • Devoxx – Project Coin, Defective Java and the Social Network

    Devoxx – Project Coin, Defective Java and the Social Network

    Joe Darcy and Maurizio Cimadamore gave a preview of the changes coming up in Project Coin. These are small changes to the Java language that will be added to Java 7. They all look pretty useful and include:

    • Strings in switch
    • Collection literals
    • <> (generic type inference)
    • Multicatch
    catch (ClassNotFoundException | NoSuchMethodException e) {
        // Do something
        throw(e);
    }

    Bill Pugh’s session was as popular as expected for his talk about defective code and how static analysis with FindBugs can help. I’ve heard Bill talk about this stuff before but this time he was emphasising that not all bugs are equal. All code has bugs but some mistakes don’t really matter.

    Google’s code has over 1000 null pointer bugs but few if any NullPointerExceptions in running code are caused by these. You need to determine which bugs are worth your time to fix.

    The most important bugs are generally those which can cost you money on the first day they manifest themselves and those bugs that occur silently. This is why Bill is a fan of runtime exceptions; if something unexpected happens, you want to know about it.

    Devoxx is held in a massive cinema complex and so after all the talks today the organisers put on a showing of The Social Network, a movie about the founders of Facebook. I really enjoyed the film. All the performances were great and I really liked the soundtrack by Trent Reznor. You don’t need to be a geek to enjoy this film. I don’t know how much of it is actually true but it paints an interesting picture of Mark Zuckerberg and draws nice connections between our concepts of ‘friendship’.

  • Devoxx – Improve the performance of your Spring app

    Devoxx – Improve the performance of your Spring app

    This talk by Costin Leau was about the new caching features in Spring 3.1.

    After going over some problems you can face when caching (stale data, thrashing, distributed caches) and different caching patterns he introduced the declarative caching of Spring 3.1.

    It uses AOP and can be declared on methods by adding the @Cacheable annotation. This annotation caches a method’s return value using it’s parameters as the key although this can be customised.

    Eg:

    @Cacheable
    public Owner loadOwner(int id);
    
    @Cacheable("owners")
    public Owner loadOwner(int id);
    
    // Using Spring expression language
    @Cacheable(key="tag.name")
    public Owner loadOwner(Tag tag, Date created);
    
    @Cacheable(key="T(someType).hash(name)")
    public Owner loadOwner(String name);
    
    // Only cache on condition
    @Cacheable(condition="name < 10")
    public Owner loadOwner(String name, Date created);

    The @CacheEvict annotation invalidates the cache:

    @CacheEvict
    public void deleteOwner(int id);
    
    @CacheEvict("owners", key="id")
    public void deleteOwner(int id, boolean saveCopy);
    
    @CacheEvict(name="owners", allEntries=true)
    public void batchUpdate()

    You can also use your own stereotype annotations. Instead of spreading @Cacheable everywhere:

    @Retention(RetentionPolicy.RUNTIME)
    @Target({ElementType.METHOD})
    @Cacheable("results")
    public @interface SlowService {
    
    }
    
    @SlowService
    public Source search(String tag) {...}

    Spring is not a cache provider itself. You plug in your own cache provider (ehcache, JBoss Cache, etc).

  • Devoxx – Performance Anxiety

    Devoxx – Performance Anxiety

    I doubt Joshua Bloch suffers from performance anxiety but it was slightly ironic that there were some technical problems before he started his talk, titled Performance Anxiety, to an absolutely packed room at Devoxx today. I knew it would be a popular session so I got there early and so managed to find a seat, unlike the others who sat on the steps or crowded the doorway.

    His talk was about microbenchmarking – measuring the performance of a small piece of code as opposed to profiling an application.

    In the good old days performance could be estimated simply by counting program instructions. Now it is simply impossible to do this because of the ‘abstraction gap’. As code has become more and more complex it has become harder and harder to estimate and measure the performance. Complexity and predictability are inversely related.

    Even benchmarking code doesn’t really work with consecutive runs often showing a variance of 20%. The code and systems are so complex nobody really knows where this variance comes from.

    The solution is to run a bunch of JVMs in sequence and then statistically analyse the data (mean, median, standard dev, etc).

    Basically, benchmarking is really, really hard and most benchmarks are seriously broken. Either the results are unrelated to the test or the error bars exceed the measured values.

    Caliper is microbenchmarking framework from Google which can help.