Pither.com

by Simon Pither, freelance developer and systems administrator

Bye Bye Prius

Posted by Simon Pither
Tue, 8 Jun 2010

Last week I said good bye to the Toyota Prius I've been driving for the last two years. I'm actually pretty indifferent to see it go. Which is quite a change from my last car, which I still miss! The Prius did at least have a little LCD with pictures of which motor is currently powering the wheels though! Despite it's inability to excite, the Prius has still served our purposes well over the last two years.

Toyota Prius

It's managed to carry a family of four with all their luggage, although sometimes with a squeeze, and keep us all quite comfortable.

For possibly the first time since I learnt to drive (over a decade ago!!), I'm now spending about a week entirely car-less. This wasn't exactly deliberate but the build and delivery of my new Skoda Fabia Estate has taken rather longer than first estimated.

Remarkably the Fabia has roughly the same fuel economy as the (old model) Prius yet has a quicker 0-62 time. Unfortunately it does have higher CO2 emissions though, so the tax is a bit higher.

The Fabia model I'm getting is brand new - they only started building them in April, so I've not actually driven a car with the exact model, engine or gearbox, so I do hope it will be reasonable. Sadly I'm not really expecting anything more than reasonable as it only needs to be a sensible, cheap family car.

One day I'll have a sports car again!

Groovy mail shot

Posted by Simon Pither
Thu, 27 May 2010

A simple mail shot script in groovy...

Runs on Debian Lenny with just a standard openjdk-6-jdk installed, groovy 1.7.2 added by hand and everything else pulled in by Grape.

#!/usr/bin/env groovy

import groovy.sql.Sql
import groovy.grape.Grape

Grape.grab(group: 'mysql', module: 'mysql-connector-java', version: '5.1.6', classLoader: this.class.classLoader.rootLoader)
Grape.grab(group: 'javax.mail', module: 'mail', version: '1.4.3', classLoader: this.class.classLoader.rootLoader)
Grape.grab(group: 'org.apache.ant', module: 'ant-javamail', version: '1.7.1', classLoader: this.class.classLoader.rootLoader)

def sql = Sql.newInstance("jdbc:mysql://localhost:3306/database", "user", "password", "com.mysql.jdbc.Driver")

def content = new StringWriter()

new groovy.xml.MarkupBuilder(content).html {
    body {
        p('Hi')
        p('This is a mail shot!')
        p('Best wishes')
        p('A groovy mail shot script')
    }
}

ant = new AntBuilder()
sql.eachRow("select email from users") { row ->
    println "Sending to: ${row.email}"
    ant.mail(mailhost: 'localhost', mailport: '25', subject: "Mailshot subject", messagemimetype: 'text/html') {
        from(address: 'mailer@demo.domain')
        to(address: row.email)
        message(content)
    }
}

The 3 Year Old Memory Aid

Posted by Simon Pither
Sun, 21 Feb 2010

In the car on the way home from a birthday party, Liz and I are trying to remember names of a few people who we all met for the first time...

I suggest one was called Paul, Liz thinks he was John, but actually John was Letty's sister's boyfriend and Paul was in fact; Paul.

Hmm, but what was Letty's sisters name?

One of her sisters was called Kitty, we can both remember that one.

"Edward, can you remember what Letty's sister is called? Not Kitty but the other one. The one who arrived late."

(A short pause for thought)

"Molly."

"Ah, yes, that was it. Thank you Edward!"

FIB 2010 Music Contest Launched

Posted by Simon Pither
Tue, 16 Feb 2010

I'm not convinced this will apply to many of the people who read this, but if you know someone in an unsigned band who fancies a chance of playing at this years FIB festival in Spain, then SupaJam's Fast Track to FIB contest has now opened it's doors.

We've only just put the contest live and the official PR launch isn't due for a little while yet, so you're now among a privileged few with early notice!

Dependency excludes in Grails 1.2

Posted by Simon Pither
Mon, 1 Feb 2010

I ended up reading the Grails code to figure this out, so I thought it might be useful to record.

One of the projects that I recently upgraded to Grails 1.2 makes use of Groovy HTTP-Builder. If you just pull in HTTP-Builder you'll quickly find that it's dependencies break your grails project. So under 1.1.1 and using maven, I had this:

<dependency>
  <groupId>org.codehaus.groovy.modules.http-builder</groupId>
  <artifactId>http-builder</artifactId>
  <version>0.5.0-RC1</version>
  <exclusions>
    <exclusion>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy</artifactId>
    </exclusion>
    <exclusion>
      <groupId>xml-apis</groupId>
      <artifactId>xml-apis</artifactId>
    </exclusion>
  </exclusions>
</dependency>

New in Grails 1.2 is dependency management via conf/BuildConfig.groovy. There are lots and lots of examples around for how to define dependencies, but significantly less on how to exclude dependencies of those dependencies. So here's mine:

dependencies {
    compile('org.codehaus.groovy.modules.http-builder:http-builder:0.5.0-RC1') {
        excludes 'groovy', 'xml-apis'
    }
}

The thing that caught me out was that there's no groupId specified on the excludes, only an artifactId.

Something else I noticed while reading the dependency code was that the dependency string matching is very limited. Only three parts (groupId:artifactId:version) can be matched. None of the other (ie type or classifier) maven parameters are supported.

Regex search and replace in Excel

Posted by Simon Pither
Sun, 31 Jan 2010

Just imagine that you have a list (a long list) of names in a spreadsheet (no, it's not suitable for export and processing as a CSV) that are unhelpfully in the wrong format. In my case they looked like "FredBloggs" instead of "Fred, Bloggs".

If you happen to be using a decent, open spreadsheet this is easy to fix as there's a "Regular expressions" checkbox on the Find and Replace dialog.

However if you're stuck with a proprietary spreadsheet life is a little harder. Excel has VB hiding in there somewhere though, so it had to be possible. Thankfully the Internet knows all and someone else has already written the code. Just to make sure I don't loose it, I'm going to reproduce the bit I found useful here:

Option Explicit

Function ReReplace(ReplaceIn, _
    ReplaceWhat As String, ReplaceWith As String, Optional IgnoreCase As Boolean = False)

    Dim RE As Object
    Set RE = CreateObject("vbscript.regexp")
    RE.IgnoreCase = IgnoreCase
    RE.Pattern = ReplaceWhat
    RE.Global = True
    ReReplace = RE.Replace(ReplaceIn, ReplaceWith)
End Function

Once that had been added to my spreadsheet as a module, I could use something like this to do my conversion:

=ReReplace(A3, "^([A-Z][^A-Z]+)([A-Z])", "$1, $2")

Yes, groups and back references are all supported (as they are in the Open Office find and replace dialog)!

Having copied the new cell down a whole column I had my results. All that remained was a copy/paste of the values to overwrite the originals with the corrected formatting.

Grails 1.2.0 (or 1.2.1 snapshot) upgrade

Posted by Simon Pither
Sat, 30 Jan 2010

Following the recent release of Grails 1.2.0 I've attempted to upgrade a few of the projects I work on. Some of these attempts have gone better than others.

For one of the simpler ones I only hit two problems.

  1. Combining Acegi with Enum's defined in the same source file as domain objects no longer works. The grails bug is here and thankfully the workaround is easy - just pull all the Enum's into their own files.

  2. Due to some of the performance improvements that Grails 1.2 makes around it's handling of GSPs and Sitemesh, the addProperty() function no longer works correctly

Unfortunately the second problem was not so easy to work around. It does however have a fix committed to the 1.2.x branch of development code. So how do you get that then? Here's what I did:

$ git clone git://github.com/grails/grails.git grails
$ cd grails
$ git checkout origin/1.2.x

You'll get some warnings about not being on a branch, but assuming you just want to build it and not modify it, you can safely ignore them.

$ ant package

You'll obviously need ant and a suitable java compiler ready to go before running this last step.

After a couple of minutes you should have a dist/grails-1.2.1.SNAPSHOT.zip file which you can unzip/install in just the same way you would a download from the grails site.

Only thing left after that is to "grails upgrade" your project again to set it to the 1.2.1.SNAPSHOT version!

Older posts