Skip to content


Saving images to a database in Grails

A domain class that contains an image (or any other binary data) would look something like this:

class Image {
	byte[] data
	String contentType
}

In MySQL the data column in the database will be a tinyblob which is generally too small for images and you will probably get the following error:

com.mysql.jdbc.MysqlDataTruncation: Data to long for column

To force it to use something bigger you would add a maxSize constraint to the data property:

class Image {
	byte[] data
	String contentType

	static constraints={
		//maxSize: 200K
		data(maxSize:204800)
	}
}

Posted in Programming. Tagged with .

Grails and dynamic controller names in UrlMappings

I was creating some REST web services and I needed to map a URL like “/api/1.0/recipes” to a controller called RecipesRestController. It took me a while to work out how to generate a dynamic controller name from the request path. The trick is not to use $controller, it doesn’t seem to work, so instead I renamed it $aController.

grails-app/conf/UrlMappings.groovy:

class UrlMappings {
	static mappings = {
		"/$controller/$action?/$id?"{
			constraints {
				// apply constraints here
			}
		}
		"/"(view:"/index")
		"500"(view:'/error')
		"/api/1.0/$aController"{
			controller={"${params.aController}Rest"}
			action=[GET:"list", POST:"save"]
		}
		"/api/1.0/$aController/$id"{
			controller={"${params.aController}Rest"}
			action=[GET:"show",  PUT:"update", DELETE:"delete"]
		}
	}
}

The GET, POST etc refer to the HTTP method. So calling the URL “/api/1.0/recipes” would call the list action on a GET request and the save action on a POST request.

Posted in Programming. Tagged with .

My iPhone App Picks

Finding good iPhone apps amongst all the not-so-great apps out there can be time consuming. Here’s some of the apps on my iPhone:

Productivity

NoteMaster - used as a replacement to the built-in Notes app

  • Syncs with Google docs. You can easily backup your notes. You can type the longer notes on your desktop.
  • Supports landscape mode - far quicker to type in that mode.
  • Supports limited formatting and images. Since it doesn’t support the full formatting on Google docs, it’s not that useful.

HanDBase - relational database, useful for storing a lot of structured information, like website logins, itineraries etc.

  • Databases can be encrypted so you can store sensitive information.
  • You can sync with your desktop if you buy an extra desktop application.
  • Available on other platforms like Windows Mobile.
  • Has some minor bugs.

Task Pro - hierarchial lists, I use it for to do lists, shopping lists etc. Lists can be hierarchial so it can handle a certain amount of complexity - for example - you might want to plan a project with it.

Travel

National Rail - national rail journey planner

  • Can save routes for quick access.
  • Live departures including platform numbers for most stations.

Zuti - offline tube planner. It could be better but it does the job - would be better to show route stages in one go, and you have to click on a drop-down to bring up the estimated time for the route.

London Bus - kind of like TFL’s journey planner, useful for non-tube journey planning

  • Can lookup an address from your current position.
  • Doesn’t always find routes.

Offline reading

iSilo - for reading websites offline. You can download a free desktop application, which you can setup to spider whole websites to read offline. For example I have it setup to spider the Sunday Times every week and then I can read it in the tube.

Byline - for reading RSS feeds offline. Caches the webpage content so you can read it offline though it’s very slow to render pages so if I have internet access I use Google Reader in Safari instead.

EBooks

Good Reader - A very good PDF reader.

Stanza - ePub reader, I prefer PDFs because of the better formatting.

Kindle - it’s finally arrived in the UK.

Social & Communication

Facebook, LinkedIn

Twitterific - simple twitter client.

Triallian - IM client, supports AIM, ICQ, Windows Live Messenger, Yahoo and Google Talk but not Facebook. Has desktop version too.

Others

PdaNet - For teathering your iPhone. (only available for Jailbroken iPhones on Cydia).

BT Keyboard - can use a bluetooth keyboard with the iPhone. (only available for Jailbroken iPhone on Cydia).

WiFiTrak - for quickly finding out about available open wifi networks, even trys to connect to a web page to check if there is web login required.

Mindjet - mind mapping software. You can share files with the very good Tablet PC version.

Networking

TouchTerm - SSH client.

VNC Lite - VNC client.

iDesktop - windows remote desktop client.

Posted in Personal Technology. Tagged with .