Archives

Tags

Showing articles written in October 2008. Show all articles

Resetting your SVN repository to a previous revision

NOTE: See the improved version of this shell script here: http://andrewbuntine.com/articles/2008/11/26/an-improved-shell-script-for-svn-resetting

For the majority of the year, I have been using Git as my preferred version control system. Recently, however, I have been using Subversion on some older projects at work.

One thing I have noticed is that the "revert" command seems to be oddly named. It's more of a svn-merge-and-undo. Maybe it's just me?

In either case, I wrote a little shell script that will act more like the Git-equivelant by allowing you to forcfully revert back to any previous revision of your project. It looks like this:

if [ $# = 3 ]
then
  currdir=`pwd`

  cd $2
  svn update
  svn merge -rHEAD:$1 $3
  svn commit -m "Reverted back to r$1"

  cd $currdir
  exit 0
else
  echo "svnreset needs three arguments!"
  exit 1
fi

Save it as "svnreset" and call it like this (the period is intentional):

$ svnreset 200 . svn://server/project/trunk

That will reset your project to r200, provided you are currently in the repositories root directory. Note also, the changes will be committed as a new revision, so if you make a mistake, just reset the reset!

I suggest that you create a symlink to /usr/bin so you can just call it straight from the terminal whenever you need it.

Loading your Rails App independently

Yesterday I found myself in a position where some horrendously ugly code just became too much for me to handle. To cut a long story short, I needed to decouple a custom library from ActiveRecord. How did it get there in the first place, you ask? Please don't. It's a tragic story...

I set up an experimentation environment (in seperation from my working app), but of course, I needed to temporarily have full access to my models, controllers, etc, etc. Now, I use version control (who doesn't?) and I could have simply branched off and started hacking. But for shits-and-giggles, I decided not to.

I played around for a while and, as it turns out, it's very easy to load your application into an otherwise independent Ruby script. All you need is:

ENV['RAILS_ENV'] = 'development'
require '/path/to/your/rails/app/config/environment'

Easy!

As a final note, it's worth pointing out that this is something that you should basically never need to do. If you simply want to automate something or perform an application-specific task, I highly recommend you write a raketask instead.

Hackers Hummus

I like to cook. I am shithouse at it.

With that said, I must mention that my recipe for easy Hummus (a Middle Eastern dip) is a fantastic addition to a late night hack-fest.

You will need the following:

  • A Large handful of Garbanzo beans (chickpeas)
  • Three tablespoons of Tahini (the sesame seed equivalent of peanut butter)
  • Dash of Lemon Juice
  • Two crushed garlic cloves
  • Salt (must be Sicilian volcanic salt, or you will die instantly)

The salt is optional. I generally don't use it, but feel free.

The method is very straight-forward. So easy infact that I am going to write it in Ruby (assuming my ingredients hash already exists):

ingredients[:garlic].crush!

bowl = Bowl.new
bowl.add(ingredients)
bowl.mash_contents_with(:potato_masher)

if ingredients.has_key?(:salt) and ingredients[:salt] != "Sicilian Volcanic"
  puts "You have 4 seconds to live"
end

bowl.serve!

Yep, that's it. You just take all of the ingredients into a bowl and mash them up, slightly adding more of a particular ingredient until you have it just right.

Serve Hummus with dipping bread.

First post!

Welcome to my new blog. I look forward to writing about a whole bunch of uninteresting shit!

I am sure eventually I will get bored or lose motivation, but while it lasts, lets see what I can come up with.

Cheers,
Andy.