Two months with Swype

July 15, 2010 – 10:30 am

I’m writing this review on my Android powered HTC Desire using a new, custom keyboard called Swype.

Swype allows you to type whilst barely lifting your finger from the screen. As the name suggests, you swype your finger from letter to letter instead of tapping. This constructs a sort of letter trail which, once you lift your finger is inspected and the top ranking word from the letters you swyped is inserted. If there is more than one match, it will offer up a list of suggested words.
Other ham-fisted, clumsy typers like me will be happy to know that the trail by no means has to pass directly over each letter. Rather, as long as the trail is roughly near a letter it will be added to the mix, albeit with less priority (I think). When you experience this for the first time you realise that there’s a lot more going on behind the scenes than you might first think.

The experience of swyping is not second nature to anyone and there is a period of time where you find yourself wanting to revert to the default keyboard. However, for the persistent and forgiving, the reward with sticking with it will deliver

The HTC Desire

May 29, 2010 – 11:28 pm

It took over at least two years, but I finally got a smart phone. An HTC Desire.

The iPhone, whilst appealing, never really seemed to end up in my possession for one reason or another. Adopting early or following the masses has never been my way. In fact, I’ll happily go the other way, with all of it’s bumps and bruises, just to show it can be done.

The HTC Desire is a fantastic phone. It’s smooth to touch and, being powered by a 1ghz snapdragon processor running Android, is also very smooth to interact with. The UI (powered by HTC’s Sense) flows from one state to the next. Nothing catches you by surprise.

Comparison to iPhone
I’m no seasoned iPhone user, however we do have one in the family which I am more than guilty of pinching for my own benefit quite a bit. The HTC Desire is in some ways a better experience.

First and foremost is that Android works on a different level to iPhone OS. Android supports multi-tasking out of the box, whereas iPhone OS will not offer this until version 4.0 is release later this year. Android phones,

Using JacksonJson @JsonSerialiser annotation for a single property

March 31, 2010 – 8:40 am

When using Spring MVC and the Jackson JSON processor recently, I needed to only expose one property from a referenced object when serialising.

Rather than have a new object defined with the single property, I used the @JsonSerialiser annotation to serialise only the property I was interested in.

I will use a ‘PublicFile’ Object as an example.

public class PublicFile {
  private String path;
 
  public String getPath() {
    return path;
  }
 
  public void setPath(String path) {
    this.path = path;
  }
}

If we were to serialise the an instance of this PublicFile Object using the Jackson Json processor, the result would be:

{
    "publicfile": {
        "path": "file path value"
    }
}

To return only the path property when serialising the instance to JSON, create a serialiser like:

public class PublicFilePathJsonSerialiser extends JsonSerializer<PublicFile> {
	@Override
	public void serialize(PublicFile file, JsonGenerator jgen,
			SerializerProvider provider) throws IOException,
			JsonProcessingException {
		jgen.writeString(file.getPath());
	}
}

And then reference it in your class:

@JsonSerialize(using = PublicFilePathJsonSerialiser.class)
public class PublicFile {
  private String path;
 
  public String getPath() {
    return path;
  }
 
  public void setPath(String path) {
    this.path = path;
  }
}

This produces:

{
    "publicfile": "file path value"
}

Mac Mini Server NAS

October 21, 2009 – 8:15 am

I’ve been pretty unimpressed with Apple’s recent hardware upgrades. I’ve not found myself the slightest bit excited by anything since the iPhone (which I still can’t justify).

Until now.

The new Mac Mini Server is totally sweet.

I’m a big fan of having a small, energy efficient, redundant system running 24/7. This new machine would fit so easily into my (an no doubt many other people’s) home network and allow me to retire my DNS-323.

The DNS-323, bless it’s heart, is an amazing little machine, but it’s lack of memory and processing power leave it hanging in the dark ages when it comes to things like databases and webservers (it just can’t run them). The mac Mini on the other hand would be more up to the task than my current iMac!

Damn the mortgage! Bring on the Mac Mini Server.

Maximizing Javascript Minimization and Readability

October 18, 2009 – 1:43 pm

By using a combination of the YUI Compressor and the Revealing Module Pattern you can maximise the effect of minimisation and, as a bonus, improve code readability.

The YUI Compressor renames local variable names and references to a single character. It can do this as it knows these variables cannot be accessed outside their function. On the other hand, it does not rename window level variables or any variable or function reference using dot notation.

Maximising Minification

An unminifiable object.

var anObject = {
 
    property: "value",
 
    doSomething: function() {
        alert(this.property);
    },
 
    init: function() {
        this.doSomething();
    }
}

Looks like this minified (with whitespace restored).

var anObject = {
 
  property:"value",
 
  doSomething: function() {
    alert(this.property)
  },
 
  init: function() {
    this.doSomething()
  }
};

Minification ratio (before whitespace restoration): 0.67 (168 to 113 bytes).

This method of defining an object does not minify at all and offers no real benefit in performance, readability or functionality. In fact, seeing as the property and function names do not minify, the coder feels obliged to name properties with the shortest names possible. More on that below.

By utilising the Revealing Module Pattern we can create highly minifiable code.

var anObject = function() {
 
    var property = "value";
 
    function doSomething() {
        alert(property);
    }
 
    function init() {
        doSomething();
    }
};

Becomes (white space restored):

var anObject = function() {
 
    var a = "value";
 
    function b() {
        alert(a)
    }
 
    function c() {
        b()
    }
};

Minification ratio (before whitespace restoration): 0.46 (172 to 79 bytes).

That’s a fair bit better!

Variable naming

Historically, to keep file-size down, Javascript variables are named in the smallest possible way limiting readability and clarity. i.e.

var el = document.createElement("strong");

Badly named variables such as this make it hard to determine the contents