Archive for September, 2009

Add an rcov c0 code coverage threshold to your cc.rb build

Wednesday, September 30th, 2009

Okay, you use rcov through metric_fu to measure your test code coverage. If you can’t compile it at least you know your code doesn’t throw run time syntax errors, right? All of it? Yeah… well, me neither. But I’m trying to get better and this is my technique for that.

Never take a step backwards. Fail your builds if the test coverage drops below where you’re currently at.

Here’s a rake task to fail the build if it drops out below a set threshold.

Add it to your lib/tasks folder in your rails app.

As you increase coverage update the threshold, treat that threshold like a ratchet, a notch of movement each time but always in the same direction.

I’m sure this is extensible to other metric_fu metrics too.

p.s., I’m very open to hearing a better way of doing this. I couldn’t get any joy from the metric_fu mailing list so hacked this together. Surely there must be a better way?

Git pull from github

Saturday, September 26th, 2009

When you create a new git repo at github some stuff wont be set by default. The following commands help from within the new repo on your own computer.

Namely, you wont be able to pull… but that shouldn’t be a surprise for you as you’re a computer programmer. You should be used to that by now.

You’ll get a message like this:

tim@thefactory:~/Documents/Development/smarterfitter(master)$ git pull
You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me either.  Please
name which branch you want to merge on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details on the refspec.

If you often merge with the same branch, you may want to
configure the following variables in your configuration
file:

    branch.master.remote = <nickname>
    branch.master.merge = <remote-ref>
    remote.<nickname>.url = <url>
    remote.<nickname>.fetch = <refspec>

See git-config(1) for details.

To fix it use these commands:

git config --add branch.master.remote origin
git config --add branch.master.merge refs/heads/master
git pull

Hooray.

N.B., if you’ve cloned the repo. from github you’re already set up with this. It is only for when you create a repository from scratch.

Self hosted CI in an evening

Tuesday, September 8th, 2009

I’m going to be outsourcing some work to oDesk which means for the first time contention on the source code repository.

Last night I set up a continuous integration solution so that the other developers and I know what’s going on with the build and so we know when we break one another’s code/tests.

Basic CruiseControl.rb fronted by Apache building on Ubuntu.

Here’s how I did it:

Our code is already hosted on github.com, it is ace.

A Linode 360 VPS from Linode for USD19.95/mo.

Sign up to running server < 5min. Ubuntu 8.04 LTS.

Execute some commands:

Configure Apache:

Download the very, truly, excellent CCMenu for notification.

This is just a rough post, if you have questions on the specifics please let me know in the comments.

It really helped that I'd written down most of these steps when I first installed our production environment so I was able to match that pretty much blow for blow.

I had to install a few testing gems that we're necessary in production to get the builds working.

Next step, install metrics_fu and have cc.rb do something useful with it all.

Lightweight business infrastructure

Wednesday, September 2nd, 2009

Monica and I run a small (niche, if you like) website called Writer’s Residence. We’ve been at it for a bit over a year, quite part time but we manage to answer support questions very promptly and provide, I think, a very good service at a decent price.

We can do this for one simple reason, infrastructure is really damn cheap now. Here’s how we do it.

Component Monthly cost
550mb RAM VPS with offsite backup @ Rimuhosting USD37.05
Skype account w/ US and UK phone numbers & unlimited international calls to landlines GBP6.95
Github hosted source code control USD7.00
Xero online accounting software w/ automated bank and PayPal feeds GBP21.50
PayPal payment processing Expensive at 5.5-6.6% of revenue but stoopid quick and easy to set up
Google Apps for our domain Free (as in beer)
Amazing software that continually beats my expectations, MySQL, Ruby, Rails, Linux Free (as in beer and speech). Thanks!
uservoice customer feedback service (we’re trying this out) Freemium w/ a good enough free account for now

With all this stuff sitting out there in the cloud and costing us nothing up front we were able to be profitable with our first 10 paying customers. We can reinvest our profit to keep building out the service.

Of course this is really the cheap stuff compared to time and there’s no way we’ve recouped the effort that has gone into this yet but it is a fun journey and as with lots of things in life it really is about the journey rather than the destination.

A further benefit of all this virtual infrastructure is that we can live and work where ever we wish within budget so long as we have broadband internet access, and that is rather freeing.