I’ve recently started using Git to deploy to my servers. Anyone who has used Heroku would be familiar with this technique and it feels kinda cool to be able to think of your different environments as just git remotes. I can’t vouch for the appropriateness of this technique in the general case, but I just wanted to make a note on what I’ve found to work for me. Hopefully, others may find this useful.

So, I use GitHub as my main source code repository, but I set up a second repository on the server I want to deploy to, normally in my home directory. First create an empty Git repo:

$ git init --bar ~/git/my-repo.git

To trigger a deployment on a push, we define a post-receive hook in this new repository. Hooks allow the you took invoke behaviour on a variety of git events, in this case we are interested in when the repository has successfully received a push.

$ vi ~/git/my-repo.git/hooks/post-receive

This is just an example, but the contents of the post-receive hook might look like this for a rack/passenger based web application:

#!/bin/bash

cd /var/ww/my-site
unset GIT_DIR
GIT_WORK_TREE=/var/ww/my-site git pull
GIT_WORK_TREE=/var/ww/my-site git reset --hard
GIT_WORK_TREE=/var/ww/my-site git submodule update -i
bundle install
touch tmp/restart.txt

Of course, this file can contain whatever you want, just make sure you set the executable bit on the file:

$ chmod +x ~/git/my-repo.git/hooks/post-receive

All that remains is to push your local repository to the new git repo on your server:

$ git remote add prod ray@my-server.com:~/git/my-repo.git
$ git push prod master

This is just a simple example, but because you are executing a script on the server, you can basically perform any functionality you like. I don’t know whether this would be a good idea in a large-scale production environment, but the key here is to make the deployments as simple and easy as possible to encourage smaller and more regular changes. Backing it with git enables a basic form of rollback, but anything that is not controlled by git, i.e. database schema state, will still need to be managed separately.

Previously I had created an Xcode plugin for Hudson to allow you to configure and invoke builds directly. Although this worked for some cases, there are a few projects where the build process is more complex or non-standard enough to force me back to scripting things manually. Rather than update the plugin to try and cope with every esoteric use case, I decided to flip things around and simple create a ruby-wrapper for Xcode. This allows me to take what i need and create custom Rakefiles to control the build process. The aim of this gem is provide an object model for navigating the project structure and be able to invoke some common types of modifications. I aim to gradually add more functionality to this gem as I come across new use cases.

The source is available on github, but it is available to install from ruby forge by using the command:

$ gem install xcoder

A simple use-case would be to find the only project in a directory, update the project’s build number and then invoke a build:

# Find the first project in the current directory
project = Xcode.find_projects.first

# Find the target called "TargetName"
target = project.target(:TargetName)

# Find the configuration called "Debug"
config = config.config(:Debug)

# Update the build number
config.info_plist do |info|
    info.version = ENV['BUILD_NUMBER']
    info.save
end

# Clean the build for this target's configuration 
config.clean

# Build the target using this configuration
config.build

# Create an IPA for this target's configuration signed using the provided identity and embed the provided profile
config.package :sign => 'iPhone Distribution: Developer Name, :profile => 'Provisioning/ProfileToEmbed.mobileprovision'

It’s early days yet, but I plan on adding support for OCUnit => JUnit output mapping (like the xcode-hudson-plugin) as well as loading provisioning profiles from the file system and generally manipulating the project file. Please send issues/feature requests to the Xcoder page on github

Blocks in Objective-C have been a life-saver and allowed our code to become terser and more understandable. Although some of the main parts of the iOS SDK have block-based alternatives (animations, etc), KVO is still based on defining a method with a well-known signature in your observer (not even defined by a @protocol and doesn’t allow the use of arbitrary @selector). I felt there should be a way to be able to achieve this and the result is this project on github.

In order to encapsulate the observation, a new instance of an object that implements the callback method signature is created for each observation and passed back to the caller. It is expected that this object is retained by the caller until the caller wants the observation to end. I’m not totally convinced that this is the best pattern, but it is at least concise and uses the existing language semantics. So, on to a simple example:

As you can see, this is very terse and means that all the code to react to changing properties can be encapsulated in the one place. The returned value is being set to a retained property so that the binding does not get dealloc’d. This observation will remain in effect until you release the returned object by setting the property to nil (as in the example) or, indeed, set the property to any other binding.

I would be very interested in feedback about whether this works for you.

Development @ 22 February 2011, “No Comments”

My AppStore apps are currently all reporting that “This item is no longer available in the App Store” or “This item is temporarily unavailable” as of couple of days ago. I have received no notification from Apple and apparently nothing wrong in iTunes connect. After a bit of googling I stumbled across this blog post where it seemed that at least one other person had experienced something similar.

I followed the post’s suggestions and updated my availability date and suddenly the app was marked as “Pending Contract”. However, all my apps are currently freebies and so there are no contracts in place, nor should there be. I filled out as much of them as I could (bar registering for GST), but to no avail.

I seem to be at the whim of Apple’s famously distant customer service right now.

Update: I eventually solved this by releasing a new version of the app, the process seemed to fix the existing app as it immediately reappeared in the app store while the new version was awaiting approval. Go figure!

I spent quite a bit of time playing with Processing.org a few years back, mainly using it for video processing (video effects, blob detection, etc) but also for 3D. I recently stumbled across a javascript port of Processing called, logically, Processing.js. This is a really nice idea, taking the established processing syntax (a subset of Java) and rendering it to a HTML5 Canvas. The Processing framework uses a “dont call me, i’ll call you” inversion-of-control pattern which makes it very easy to get something up and running but that, and the fact that it is not standard javascript, can make it tricky to integrate.

I also found a very slick library called three.js which I used to create the header animation on rayh.com.au. It provides a basic set of 3d concepts such as points, lines, renderer, camera, etc which can use to draw and animate basic 3d scenes. There is no special loop function, you just use setInterval to trigger your animation to update every once in a while.

My personal site, rayh.com.au, was in need of dire attention. I had originally made it a flat html/js/css site to show off some jQuery skills. However, even though I really like the idea of a site built entire from static files (damn fast) and using javascript to drive the dynamic elements, it is not search engine friendly.

Biting the bullet, I decided that I needed some sort of server-side scripting. By day, I mainly use Java and sometimes Ruby. So my choices seemed to be Java, Ruby or PHP. Many moons ago, I was a PHP developer and I bailed out of that technology in favour Java. For me, PHP just sucks in far too many areas for me to adopt it for a one-off tiny website, but the reasons why is another story. Java seems way to heavyweight and verbose for my needs and so Ruby seemed like the natural choice.

Previously I had used Rails for projects, but it’s full-stack solution was still too much for my needs as my site has no database access. This led me to look at Sinatra, a super lightweight and declarative approach to a web application. I simply converted my existing html file to a .erb and told Sinatra:

require 'rubygems'
require 'sinatra'

get '/' do 
  erb :index
end

This code is pretty much all that is needed to get up and running. It tells Sinatra that when a user accesses the root of the site using GET, serve the index.erb file from the views/ directory. This approach allowed me to just add the features I needed to perform the simple set of requirements I had rather than trying to convince Rails to do less.

When it came to deploying the app, I used Passenger (AKA mod_rails) with apache which was an absolute breeze. I highly recommend this approach if you need something more powerful than simple javascript & html without resorting to full-stack web application frameworks or ugly php scripts embedded in html.

Over the last couple of days I’ve been working on a Criteria for ActiveRecord. The concept is quite simple; rather than writing strings of SQL to pass to the find() method, we build the criteria using an object-orientated approach. Anyone who has used Hibernate, Torque, Propel et al will know how powerful and useful this can be.

For example, imagine you have a series of filters, all of which may, or may not, add constraints or expressions to your query. Each filter will need to append it’s own SQL to the end of any previously generated SQL and may even need to introspect the existing SQL to determine if its doubling up on statements or resolve potential conflicts.

With Criteria this becomes simpler. For example:

criteria = Criteria.new
criteria.and do |c|
  c.or User.role.eq(:admin)
  c.or User.active.eq(false)
  c.or User.createdAt.gt(10.hours.ago)
end
criteria.and do |c|
  c.or User.role.eq(:editor)
  c.or User.active.eq(true)
  c.or do |c2|
    c2.and User.createdAt.gt(20.days.ago)
    c2.and User.createdAt.lt(10.hours.ago)
  end
end
users = User.find(:all, criteria)

We could, at any point, introspect the state of criteria by calling:

criteria.ands.each do |c|
  put "AND #{c}"
end
criteria.ors.each do |c|
  put "OR #{c}"
end

And, finally, we can remove arbitrary bits of criteria:

criteria.ands.delete_at 2

I hope to have a release out very soon, but for the time being some more examples and API docs are on the Criteria project page on RubyForge

Development @ 30 September 2007, “No Comments”

I have been looking around for a way in which to set Swing client properties easily in JavaFX, without subclassing the whole widget. This seems like the simplest (and most obvious, in hindsight) way of doing this. Documentation is still a bit thin on the ground so I am unsure if this is the proper way to do things:

trigger on (new Button) { button.putClientProperty("Quaqua.Button.style", "placard"); }

The above code allows me to inform the underlying Quaqua LookAndFeel that I wish to use the placard button style. If I wanted to use this selectively, I would have to subclass Button.fx, provide an additional attribute (say style) and then apply the property if the attribute is set.

Obviously, you need to know the internal name for the Swing component you are trying to access, this API documentation is pretty helpful for that.

I have just decided to upgrade Eclipse, and thought it best to start from scratch. I do a lot of work in Java, PHP as well as Ruby on Rails and so I tried to set up an integrated environment using Eclipse. I have documented the steps here as much as a reminder for myself as a guide for other people trying to something similar.

First, download and unzip the Ecipse + J2EE package from http://www.eclipse.org/downloads/. You do not need to ‘install’ Eclipse as such, just put the uncompressed directory somewhere logical (/Applications on a Mac, for example).

  1. Launch Eclipse :P
  2. Select: Help -> Software Update -> Final and Install.
  3. Select Search for new features to install
  4. Check the Europa Discovery Service
  5. Select Add Remote Site
  1. Type in name: Aptana (For javascript support)
  2. Type in url: http://update.aptana.com/install/3.2/
  3. Select OK
  • Select Add Remote Site (For Ruby on Rails support)

    1. Type in name: RadRails
    2. Type in url: http://update.aptana.com/install/rails/3.2/
    3. Select OK
  • Select Add Remote Site (For SVN integration)
    1. Type in name: Subclipse
    2. Type in url: http://subclipse.tigris.org/update_1.2.x
    3. Select OK
  • Select Add Remote Site (for PHP support)

    1. Type in name: PDT
    2. Type in url: http://download.eclipse.org/tools/pdt/updates/
    3. Select OK
  • Select Add Remove Site (for Hibernate support)
    1. Type in name: Hibernate Tools
    2. Type in url: http://download.jboss.org/jbosside/updates/development
    3. Select OK
  • Select Finish
  • Select your nearest mirror, when prompted
  • Select Eurpoa Discovery Site -> Programming Languages -> Ruby Development Tools
  • Select PDT
  • Select Aptana
  • Select RadRails
  • Select Subclipse
  • Select Hibernate Tools
  • Select Select Required (to resolve dependencies)
  • Select Next
  • Accept the agreement(s) and select Next
  • Select Finish
  • Go for a walk.
  • Phew, so after all that, you should have an Eclipse IDE set up to support PHP, Ruby, Rails, Javascript, Java, Hibernate and Subversion. You can, of course, select many other tools from the Europa discovery site for other development tools, graphical editing and the like.

    Windy Road has a nice article on the use of Javascript And Hidden Applets, what they call JAHA.  This is similar to the technique I have used in Robonobo, however I am having all sorts of issues on Mactel Firefox, possibly due to the Apple MRJ / Firefox integration.

    It would be nice to have a small js library that allowed you to dynamically instantiate and destroy embedded, hidden applets.