Scottish Blogs.com


Timestamps that can behave like booleans via Notes from a messy desk April 10th, 2008 at 17:25

image I often come across this particular use case and it’s probably easiest to explain with an example. Take an ActiveRecord model called Book which represents a book in Amazon’s catalogue. In addition to books which are already published, we collect information about books which are going to be released at some point in the future. We store the publication [...]...

Scotland on Rails Registration Open! via Notes from a messy desk February 17th, 2008 at 10:56

image Registration for Scotland on Rails has now opened! With Keynotes from Michael Koziarski (nzkoz) and David A Black, along with another 15 Rails luminaries doing talks on bleeding-edge topics, it’s set to be the best Rails conference this side of the pond! The conference is on Friday 4th April - Saturday 5th April, with a [...]...

Tabular FormBuilder for easily creating forms in Rails via Notes from a messy desk July 13th, 2006 at 12:11

image OK, HTML forms. There’s a bit of a nightmare. How do you style them so that they are semantically correct, but look good on all modern browsers? I’ve tried in the past, and I’ve failed pretty miserably. There’s a couple of options out there: Prettier Accessible Forms Awesome Forms but they have their quirks and disadvantages too. So I decided to be irritatingly pragmatic for now and use tables. I know, it’s not right, but it’s good enough, OK? So, I created a form builder to produce them. Actually I first created it back in May, but I’ve finally gotten around to using it in anger, so it’s been tidied up a little, and a few features added. You can grab a copy from my plugin repository with the following magick juju:...

Using the shell within irb via Notes from a messy desk July 12th, 2006 at 11:50

image A couple of weeks ago, I had a little diversion, playing around with the shell bits and pieces in Ruby core. And it sounded like it could be quite handy for when you’re in that IRB session and don’t want to quit/reload (or switch to another terminal, I guess). So I added a few widgets to by ~/.irbrc to make it work well for me. You can find the relevant parts in shell_from_irb.rb. Probably the easiest thing to do is copy and paste the contents into your own ~/.irbrc. So, how do you use it? From the irb shell: irb(main):003:0> shell.echo 'hello world' => hello world Or, something more useful which will return you an array of files you’ve modified since your last commit to subversion: irb(main):016:0> shell.svn(:stat).grep(/^M/).collect do |line|...

Of consulting and developing and spending money via Notes from a messy desk June 20th, 2006 at 14:22

image Finally, I feel that I’ve fully caught up with all the bits and bobs that needed doing while I was on holiday, in addition to the regular work I had on last week. Setting up meetings, chatting with people, encouraging folks that they want me to do work! I seem to have a bit of a lull for the rest of the week now. In some ways this is nice (I can actually get on with some development work that has been starved of resources for a few weeks now), but in other ways it feels slightly disconcerting. After all, I’m a contractor. I work on an hourly rate. So when I don’t have stuff to do, it means nobody is paying me! OK, it’s not so bad, because a couple of people pay me just to be there when they need me. So what am I up to? Well, the development of the new...

The Joys of Rails via Notes from a messy desk January 27th, 2006 at 08:47

image The past week or so has been interesting. I’ve been doing a lot of development in my spare time, with Ruby on Rails, putting together a basis for three different projects. OK, since I haven’t got all the spare time in the world ever, I should really be focusing on getting one of those projects to a releasable state before fiddling with the rest, but I’m just so infused with ideas right now that I can’t help myself. Test Driven Development. That’s part of what’s doing it for me. I write a bunch of tests which allow me to clarify the API of a particular function, or method or class. “When I say this, the function will do this.” What better clues can you have as to how to implement it? And the joy of having the test suite pass after...

Howto: Using Switchtower with Ruby on Rails and DreamHost via Notes from a messy desk January 22nd, 2006 at 18:31

image Finally, I’ve decided to investigate using Switchtower to deploy Ruby on Rails applications. And, since my hosting company of choice is DreamHost, I thought I’d share my recipe in case it was useful to others. First things first, let’s create the Subversion repository. I’m actually hosting my repositories over at CVSDude these days — I got bored waiting for DH to make an svn offering that people are clamouring for and they offered me free space so long as I link to their site from my blog. Hence the frog on the sidebar. Anyway, so I’ve created a brand new repository just for this project, Stories, with the usual trunk, tags and branches layout. Create a skeleton rails project in there, adding the necessary bits to the repository. (Actually, maybe...

Ruby and Amazon via Notes from a messy desk January 21st, 2006 at 17:52

image Well, that’s been a fun day of geeking. I’ve spent most of the day writing a small Ruby module which will talk to Amazon’s E-Commerce Service nicely. It’s been an interesting experience, particularly since I really don’t know Ruby all that well (embarrassingly, it took me about 10 minutes to figure out how to iterate through a list — I’d forgotten to use the .each method!). But I’ve now got a basic item lookup which will return an item from the Amazon database given an ASIN. Which is actually pretty much all I need for my other nefarious plan (more on that when it’s actually closer to fruition!). I still need to tidy it up and write some documentation. The one thing that I actually got to do today, though, was practice Test...

More handy shell shortcuts via Notes from a messy desk January 19th, 2006 at 13:42

image Regularly when I’m working at the shell, I realise that I’m repeating the same sequence of commands over and over. Or that doing something a little bit extra would be so useful. Last night’s effort was two-fold; one to run a command and give my Terminal window a title (useful for long-running applications where it helps to remember which iTerm tab they’re hiding under) and one to start a Rails application locally: # General thing to set the window title to something or other before running # a program. Intended for daemons that don't background so you know which # iTerm tab they are running in. title() { echo -ne "33]0;$107" shift $@ } # Just like my zoperun() shortcut, let's have one for Rails apps. The only # real bonus is that it sets the...