Category Archives: Ruby

Using the ‘after_party’ gem with Capistrano 3

One of my long-term client projects involves frequent data migrations (as opposed to the classical schema migrations one typically runs).

Up until recently I’ve been creating standalone rake tasks to perform the data migrations and executing them manually when deploying to Staging and Production.

Of course, the dangerous word in the above paragraph is ‘manually’.

This isn’t too much of an issue for Staging as I’m coming fresh from developing the rake task and it at the forefront of my mind. No, the real danger is that by the time Staging gets shunted over to Production I’ll invariably  forget to run the data migration, regardless of however lurid the colour I mark the task with  in a Trello label.

Enter the ‘after_party’ gem by Steve Mitchell.

With this fantastic gem I still get to write the migrations as tried and tested rake tasks, but these tasks are registered in a ‘task_records’ table, similar to schema migrations when executed, so they are only launched once.

The only issue I’ve had is integrating it with Capistrano 3. For those with similar struggles below is how my config/deploy.rb file is setup.

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      execute :touch, release_path.join('tmp/restart.txt')

  after :publishing, :restart

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      within release_path do
        with rails_env: fetch(:rails_env) do
          execute :rake, 'after_party:run'

XCode Project Template bug on Snow Leopard

After a gap of almost six years I’ve been grabbed by the sudden urge to start doing some Cocoa development again.

Rather than get my old battered copy of Hillegass’ seminal Cocoa Programming for Mac OS X out of some long forgotten cupboard I’ve been refreshing my fading memory by reading the new Cocoa Programming title from the Pragmatic bookshelf, which, although still in Beta, is so far a nice breezy ride (back) into the world of Mac development, and more importantly for me these days, is available as a downloadable PDF – unlike the Hillegass title (sort it out, man!)

Everything was going well until I hit a chapter that claimed that I should have an application delegate class automatically created when starting a new vanilla ‘Cocoa Application’ project.

I didn’t.

Fighting my ‘this is obviously a Beta book problem’ mentality, I slowly discovered that my XCode installation is doing very strange things, even after totally wiping out my current installation and replacing it with the latest download from the Apple site (v3.2.1) creating a new basic ‘Cocoa Application’ would not give me the delegate files (and instead of the newer Xib Interface Builder format, I had the older style Nib format).

Very strange indeed.

Digging deeper into the mysterious world of XCode templates (i.e. poking randomly around the contents of /Developer/Library/Xcode/Project Templates) I discovered that yes, my Cocoa Application template folder, which is used as the basis of new projects, looked a bit suspect :

drwxrwxr-x   9 root   admin         306 May 18  2009 Cocoa Application
drwxrwxr-x   9 root   admin         306 May 18  2009 Cocoa Document-based Application
drwxrwxr-x   4 root   admin         136 Sep 24  2007 CocoaApp.xcodeproj
-rw-rw-r--   1 root   admin         157 Sep 24  2007 CocoaApp_Prefix.pch
drwxrwxr-x  10 root   admin         340 May 18  2009 Core Data Application
drwxrwxr-x  11 root   admin         374 May 18  2009 Core Data Application with Spotlight Importer
drwxrwxr-x  10 root   admin         340 May 18  2009 Core Data Document-based Application
drwxrwxr-x  11 root   admin         374 May 18  2009 Core Data Document-based Application with Spotlight Importer
drwxrwxr-x   4 root   admin         136 Sep 24  2007 English.lproj
-rw-rw-r--   1 root   admin         849 Sep 24  2007 Info.plist
-rw-rw-r--   1 root   admin         596 May 18  2009 TemplateChooser.plist
-rw-rw-r--   1 root   admin         263 Sep 24  2007 main.m

i.e. what the blazes are those “Core Data…” folders doing there? They are Project Templates in their own right and shouldn’t be within this folder.

Throwing caution to the wind (well, backing up the folder first) I pruned out these folders, plus the “Cocoa Document-based Application one” and the “TemplateChoose.plist” for good measure. Leaving it looking like :

drwxrwxr-x   9 root     admin         306 May 18  2009 Cocoa Application
drwxrwxr-x   4 root     admin         136 Sep 24  2007 CocoaApp.xcodeproj
-rw-rw-r--   1 root     admin         157 Sep 24  2007 CocoaApp_Prefix.pch
drwxrwxr-x   4 root     admin         136 Sep 24  2007 English.lproj
-rw-rw-r--   1 root     admin         849 Sep 24  2007 Info.plist
-rw-rw-r--   1 root     admin         263 Sep 24  2007 main.m

and all seems well within the XCode world again.

I’m afraid I have no idea what could have caused this, and the only other reference I can find to the problem is here which ties up exactly to what I was seeing, and proves it’s not an isolated incident.

Interested to learn if anybody has had a similar problem, and what the possible cause(s) are as I’m sure if it affected all Snow Leopard / XCode developers it would be more widely known about.

Old App Traffic Spike


Many moons ago (well, late 2006) I wrote my first Rails application, a dinky little GTD app named ZenLists.

Now, I haven’t given the app much though for the last eighteen months, and the shocking confession is I don’t even us it myself anymore (I’m currently using a dazzling array of windows instead which I may cover in a future post) so I was surprised when casually browsing my site stats to see that there’s been a large traffic spike and a surprising number of registration e-mails coming my way.

That got me thinking either I’ve been spammed or some web design guru has put me on a list of ‘when CSS designs go bad’ type list as the interface is pretty crude, even by 2006 standards, but no, it looks like the app has been briefly mentioned in a list from Mashable of GTD apps.

That got me thinking, I really should do what the Cool Kids do and stick the code up on GitHub or something, as there’s the kernel of a half-decent application there, even if the code is a bit crufty by modern Rails standards.

Hmm…maybe I should also open-source the ‘DigiGuide for Mac’ clone I developed whilst watching the Superbowl about 5 (!) years ago. I just dusted it down in XCode and I’m amazed to see it actually still works! OK, it doesn’t do much apart from download TV data and allow you see select a channel and see what’s on, but again, it could be the basis of a very useful app without too much effort.

Crumbs, makes me wonder how many unreleased apps are lying dormant on geek hard drives around the world, that with a little brush of the TLC wand, might be of use to someone.

Ioncube for Rails?

Having just completed my first mISV product, I’m already starting to think about potential new projects.

Despite Datafeed Studio being written in PHP, it is fair to say it is not my programming language of choice.

Datafeed Studio is a web application that is installed by the end user on their server, thus it made sense to go for for the language that has the biggest support amongst web hosting services.

Of course, now that mod_rails / Passenger has been released, hopefully it wont be too long before Ruby does some catching up in the widespread availability and ease of deployment stakes. I understand that major web hosting providers such as Dreamhost are already offering support.

The second reason I chose PHP is to do with script protection. There are several PHP solutions out there to encode scripts to prevent piracy such as Zend Guard, Code Lock and IonCube (I opted for the latter) but seemingly none for the Ruby world?

My previous Rails projects have been SAAS based so I’ve never had to worry about this – but I have a mISV idea that like Datafeed Studio, would require the customer to install the software on their server, but the lack of script encoding / protection does unfortunately put me off using Rails in this instance.

Has anybody else been in this position? What did you do? Am I worrying too much about piracy concerns?

Rails Deployment: Lessons Learned from James Duncan Davidson

James Duncan Davidson has published an excellent essary detailing Rails deployment issues. Jam-packed with practical tips.

* Should I use CGI or FastCGI?
* Should I use lighty or Apache httpd?
* If Apache, which freaking version?
* And how do I configure mod_fastcgi with Apache?
* Should I let the webserver manage fcgi processes or spawn them externally?
* And what’s this SCGI thing?
* And what’s this SwitchTower thing?
* What version of MySQL is the server running?

Link : Real Lessons for Rails Deployment