Recent Posts in the Blog
11
MAY
Git & git-export
Posted by Adam Posted in Programming and Software 0 comments
Over the last few months there has been a lot of talk on the internet about Git – a distributed version control system which seems to be becoming ever more popular within the Rails community. Because of this, I thought I’d follow (sheep like?) the trend and look at moving some of my projects into git repositories. I have started doing this and am now a proud, fully-paid-up, member of github (a nice little git repo hosting service). I do plan to setup my own remote git “store” in the future, but for now, until I have the time to transfer all our subversion content to git – github will do nicely for my current projects.
I could go on about how git is different to SVN and so on, but this topic has been covered to death on the internet so I won’t, but, what I do want to let you see is a quick ruby script I knocked together to simulate the behaviour of svn export http://svn.domain.com/myrepo in git. This takes the form of git-export my_repo git://mydomain.com/repo.git my_branch
You can check it out in my new github account at http://github.com/adamcooke/git-exporter/tree/master/exporter.rb – I have copied it to /usr/local/git/bin/git-export so I can simply run git-export from anywhere on my system.
If your reading this and have any suggestions to improve it, please don’t hesitate to fork the repo and send it over :)
28
APR
As UK iPhone users will know, we still don’t have a nice & easy way to create ringtones of our iTunes Music. To me this seems a little unfair, especially considering how absolutely rubbish the default ringtones on the phone are.

So after hearing “Strum” one too many times I decided to create a few ringtones based on TV & film themes to pop onto my iPhone and I now I have the ‘Grandstand’ theme as my ringtone – woo!
To say all that and not publish my the fruits of my labour would be just mean, so I’ve zipped up 13 files for the following TV shows/films.
- Countdown
- Fame Academy
- Grandstand
- James Bond – big
- James Bond – original
- Matrix
- National Lottery Balls
- Play your cards right
- Radio 1 Newsbeat
- Strictly Dance Fever
- The Apprentice
- The Bill
- X Factor
To install these onto your iPhone simply open up iTunes and drag the files into your ‘Ringtones’ page.
Download Pack 1 (5MB, ZIP compressed file)
15
APR
Enjoying your SVN Time
Posted by Adam Posted in Software 4 comments
Since moving from my Windows PC to my Mac last year, I’ve always have the problem of managing anything with Subversion. In Windows, I had the luxury of the fantastic TortoiseSVN which handled every SVN need I had however on the Mac there is no such software. OK, RapidSVN and svnX try to be good clients, but they simply don’t live up to the high standards set by the TortoiseSVN guys.

So, I had to decide – do I really want to boot up a Parallels install each time I want to commit or update my code? Of course I don’t, so I started playing with the plain old SVN command line. Although, I’ve always used it for quick checkouts, exports, commits and updates I’d never used it for managing a large project where files get added, deleted & moved around on a regular basis so it was time to use it mainstream!
I thought I’d post up a very quick entry about what things I use and how it’s so easy once you get the hang of it.
The two most useful commands during your project’s life cycle will be svn up and svn ci which will update and commit your code respectively.
Update your code before committing
I strongly advise always running an update before a commit – this will ensure that code you commit is at the latest version stored in your repository. It will update your local code to match that in your repo and merge (as best it can) your changes with those which have been committed since your last update.
When you run svn up (from within your working copy), you will be presented with a complete list of all the files which have been updated and each file will be prefixed with a letter – A (added), M (modified), D (deleted) or C (conflicted) are the most common.
Once complete, you should check this list for any files which have conflicted – this means SVN couldn’t work out how to automatically merge the changes it downloaded with those on your local machine and you need to merge them yourself. If you browse to the folder where the file with the conflict exists, you will see 3 extra files – filename.r24, filename.r26 and filename.mine – these files represent the version which matches your working copy revision, the latest in the repository and the copy you have. It is now completely upto you to make sure your local copy, includes all the changes which others may have made using these newly created files as a point of reference.
When you’re happy with your merge, simply type svn resolved path/to/filename to remove the extra files thus marking the file as resolved.
(Rails App Tip: if your developing a Rails application, I advise you to now also run an rake db:migrate to update your database schema.)
Committing your code
Now you’re all up-to-date you can send all your updates to the server. But… wait… you need to check something first!
To check what changes your about to commit simply run svn status (inside your working copy). This will return a list of files similar to that provided by the update command and, as before, each of these will also be prefixed with a letter – A (newly added), M (modified), D (deleted) and ? (not added yet, but in the working copy). As above, you don’t need to worry about A, D and M – SVN knows what it’s going to do with these however, you do need to keep an eye on ?.

The question mark (?) means that you have put a new file in your working copy but it hasn’t been properly added to SVN. To add these files you need to run svn add path/to/new_filename – this will add it and any new output from the status command will show an A rather than a ?.
If you have lots of these files, you can use the useful command below to simply add every file marked with a ? – this is a real time saver if you’ve just added a folder of images or copied in files from another folder.
svn add `svn status | grep "\?" | awk '{ print $2; }'`
Once, you’re happy with the output from svn status, you can proceed to actually commit the changes by running svn ci. When you run this command, your default text editor will open and ask you to enter a commit message – this should outline all the changes you made in this revision – it’s useful to make this as detailed as possible but don’t spend too much time on it.

In summary
This post only covers the very basics of Subversion – there is so much more – svn revert, svn diff and lots of other useful commands which you’ll need to learn if you want to switch all your SVN usage to the command line.
If your sitting there angry with your SVN client app – don’t be scared to explore the wonderful world of the command line. It’s nowhere near as scary as it’s made out to be.
But… please, please, please take a full backup before exploring any new things!
Other resources
The SVN Book is free to download – have a look.
Why not take a look at this basic work cycle for a little more info about the commands available to you.
If you have any questions, please don’t hesitate to post a comment.
01
MAR
Site updates & moved to SliceHost
Posted by Adam Posted in This Site 2 comments
For the last week or so I’ve been working on updating some of the things on this site which really deserved an update. For example, the twitter & flickr feeds both seriously needed a re-vamp – they were stagnant and rarely updating correctly.
Updated Twitter & flickr feeds to use live data
Before, both my flickr and twitter feeds used to use their respective APIs to download new updates using a cron job on the server every 5 hours. This solution worked well enough and ensured the site loaded quickly, however the updates weren’t frequent enough and data was very quickly out of date.
To address this problem, I had two options: firstly, I could have changed the cron job frequency to run every 15 minutes or secondly, I could have re-thought the process entirely… I choose the second.
The twitter feed now uses an AJAX call to a page on my site, which then queries the twitter API (unauthenticated to avoid the 75 requests/hour limit), excludes any statuses starting with an @ symbol, formats them into some suitable XHTML and pops them into the correct place on the page. This AJAX call is initiated on page load so the page is fully loaded before the call takes place (i.e. the site is usable even if twitter is being slow/down). If there are any errors or timeouts from twitter, the errors are caught and a nice message will display instead of my latest statuses.
The flickr feed is much more simple – in fact, it’s just a flickr badge (http://www.flickr.com/badge.gne). I’m not entirely happy with this because it only display two columns of pictures rather than the three I had before. I did consider approaching this in the same way as the twitter method but, as the badge is working nicely, why over complicate things?
New Logo
The original logo was never meant to be a permanent thing, in fact, it was included in the original concept/visual and then I never replaced it before build and it stuck. The new “logo” (and I use logo in the loosest sense of the word – it’s just a typeface with colours!) appears in the top left of the page and in error messages.
Syndicate link removed from navigation
There used to be a link to page which contained links to various RSS feeds (blog, twitter & flickr) in the main navigation, however, after a few moments thought I decided that anyone wanting to subscribe to my feed would easily notice their browser’s RSS icon and click it. The syndicate link has now been moved down to the footer and replaced in the top navigation with a ‘My Projects’ page which will have some details of things I’m working on or have been working on recently.
Moved to Slicehost
If your reading this post, your reading it from my new slice at Slicehost. I signed up for a very basic 256MB slice at the weekend and, so far, things have gone very smoothly – Slicehost have really figured out the right way to do virtual server (VPS) hosting IMO.
One other change…
There is, of course, one other quite signifiant update however I will post something about this in the next day or so.
29
DEC
Colour Picker Rails Plugin
Posted by Adam Posted in Rails Plugins 9 comments
A useful form helper to provide an easy to use colour picker field. Using this plugin you can simply provide a colour field with an integrated javascript colour picker.

Installation Instructions
1. Install the plugin into your Rails application
./script/plugin install http://svn.plasticrain.com/stuff/rails/plugins/colour_picker
This will automatically copy some required resources into the appropriate locations. The colour_picker.js file which powers all the javascript actions will be copied into public/javascripts. Also, a new folder will be created in your public/images folder to contain two required images – a spacer and alternative button icon.
You need to include the javascript in your application’s layout.
<%=javascript_include_tag 'colour_picker'%>
Within your form, simply call the ‘colour_field’ method:
<%=colour_field :object, :method%>

Usage Examples
Use the colour field with a graphical swatch icon rather than a button:
<%=colour_field :object, :method, :use_swatch_icon => true%>
Change the label of the default button:
<%=colour_field :object, :method, {}, {:value => 'Choose a colour' }%>
Code
Subversion – http://svn.plasticrain.com/stuff/rails/plugins/colour_picker