Page updated 2008-11-13: Talks by Clinton R. Nixon.

Relentless Automation, or Useful Stuff Roundup

I recently read Neal Ford’s The Productive Programmer and it was fantastic. One of the key points in it that hit home was that you should automate anything you have to do twice, even if it takes longer to automate than it would to do it by hand, as you’ll probably have to do it many more times. With that in mind, I’ve been using others’ and my own automated tasks way more often. Here’s a roundup of the most useful stuff I’ve found or created:

Quickly jumping to projects

Muness Alrubaie wrote a good post on how to automatically create aliases to cd to your projects. Being able to jump to my weblog by typing crnixon.org or to my spect project by typing spect has been super useful.

Reading gem source code

I read the source code to gems I’m working with for documentation all the time. I used to have an alias, so I could type egem capis and it would open the capistrano gem. Unfortunately, it just did an ls | head -1, so it’d grab the first gem directory that matched the argument.

gemedit is a way better implementation of that. It not only prompts you if your argument is ambiguous, but it also has bash completion built in. Add the following to your .profile and you’re set:

complete -C "/opt/local/bin/gemedit --complete" gemedit

Rake completion

Speaking of completion, I might as well add it to rake, right?

export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/}

_rakecomplete() {
  COMPREPLY=($(compgen -W "`rake -s -T | awk '{{print $2}}'`" -- ${COMP_WORDS[COMP_CWORD]}))
  return 0
}
complete -o default -o nospace -F _rakecomplete rake

Great! Now I can eliminate even more typing.

My ultimate automation tool, Thor

There’s a lot of tasks I do all the time: provision new boxes for Rails, start new projects, setup Apache virtual hosts, and put my SSH key on a new machine, just to start. I could write a separate script for each of these, but it seems like I should be able to collect and distribute these tasks, similar to rake tasks. Yehuda Katz wrote a tool called Thor a few months ago that fits the bill perfectly. It’s a lot like rake, but it deals with command-line arguments sanely, uses standard Ruby classes, and has a script management system.

Usting Thor and Capistrano, I’ve now got a script that provisions an Ubuntu box from the base install to a full Apache + Passenger + MySQL Rails stack. Each one of the tasks above, I was able to easily script, and I’ve put all my scripts on GitHub. Adding cypher’s thor-git scripts on top of those has taken my automation-fu to a new level.

And, of course, I couldn’t use Thor without bash completion:

_thorcomplete() {
  COMPREPLY=($(compgen -W "`thor -T | grep -v "^\-\+\|Tasks" | awk '{{print $1}}'`" -- ${COMP_WORDS[COMP_CWORD]}))
}
complete -o default -o nospace -F _thorcomplete thor

Planning for OSCON

I’m attending O’Reilly’s Open Source Conference for the third year in a row this week, and I’m getting really excited. I normally write my preview and planning post earlier, but I’ve been slammed getting my 3 hour tutorial presentation ready.

Anyway, here’s what I’m most excited about this week:

Monday

Well, first off, I talk at 8:30 in the morning. Seriously, thanks to whoever’s responsible for that. I get to talk and be done with it and can relax for the rest of the week. Last year, I talked on Thursday afternoon, and it had me on edge the whole conference.

I was really torn on how to spend my afternoon. There’s a tutorial on Django that was tempting me, but I think I’ll be going to Memcached and MySQL: Everything You Need To Know. It’s directly applicable to my job, and a sysadmin from Six Apart and a head guy at MySQL probably know a heck of a lot of stuff. Might be dry; definitely will be full of info.

Tuesday

I’m jazzed about Tuesday morning. John Resig of jQuery fame is giving a tutorial on Secrets of JavaScript Libraries. This promises to be awesome.

Tuesday afternoon was a head-scratcher. Nothing particularly grabbed me, so I’m going to head to Practical Erlang Programming. I hit up Simon Peyton-Jones’ “A Taste of Haskell” last year, and it was the best part of the conference for me, so maybe this will surprise.

Wednesday

Sessions start on Wednesday, so I’ll be seeing a lot more stuff. On the Ruby front, I’ve got An Introduction to Ruby Web Frameworks, What Has Ruby Done for You Lately? (this one looks great), Web Frameworks of the Future: Flex, GWT, Grails, and Rails, and Building a Bayesian RSS Aggregator in Ruby. I’m pretty stoked about all those.

For my wild-card sessions, I chose Creating & Supporting Free Software in Africa: the African Virtual Open Initiatives & Resources (AVOIR) experience and Running a Successful User Group. Open source in Africa is a particular interest of mine, and I’m keen on starting a new developers’ user group in Durham, so I have high hopes for these.

And then, the best part of OSCON: FOSCON. The Portland Ruby Brigade puts this on each year. There’s free food and great presentations. This year, there’s a live coding competition between Rails, Seaside, Django, and some PHP frameworks. There’s also Ed Borasky, who gave one of the densest presentations at last year’s RubyConf.

Thursday

Thursday’s got a lighter amount of Ruby presentations. I’ll be hitting up Sam Ruby talking about Ruby 1.9 and Brian Ford talking about Ruby performance. Excited about the first; cautiously ambivalent about the second. I have a feeling it’ll be about Rubinius, and while Rubinius is cool, it’s not my thing. Maybe it’ll be my thing afterwards.

The rest of my day will be filled with Skimmable Code: Fast to Read, Safe to Change, Wonderful World of MySQL Storage Engines, Code is Easy, People are Hard: Developing Meebo’s Interview Process, and the one I’m looking most forward to, Just Enough C for Open Source Projects. I know C, where “know” is defined as “can kind of read it and can manage to code trivial programs in it.” I hope I’ll come out with some tips on how to polish up my C skills.

Because I used to be a Perl nut, and also find Larry Wall entertaining, I’ll definitely be at the State of the Onion.

Friday

Friday’s a short day, and to be honest, there wasn’t much stuff that grabbed me. I am excited to hear Roy Fielding talk about REST, and I’ll hit up the Free Geek Tour that afternoon. My flight doesn’t leave until late, so hopefully I can send some of the afternoon just walking around.

Page updated 2008-07-13: About Clinton R. Nixon.

Solve Your Keynote And TextMate Woes With Webmate

So here’s a very small target market: people who use a Mac and use Keynote presentation software and also need to open files in a text editor called TextMate from their presentation and are comfortable running Ruby scripts on the command line: in other words, just about every Rails developer I know.

I’m giving a tutorial presentation this summer on Rails plugins and I wanted to be able to make links in my presentation using the TextMate URL scheme to open up plugin files in TextMate. Keynote, however, tries to be very helpful and silently removes the link you’ve just typed if it doesn’t start with http or https.

What I need is a proxy, so I wrote one using Sinatra. That TextMate URL scheme is ugly as sin anyway, so this is useful even if you aren’t in my unique situation. Here’s the script:

require 'rubygems'
require 'sinatra'

get '/*' do
  file, line = request.path_info.split(/:/)
  local_file = File.join(Dir.pwd, file)
  if (File.exists?(local_file))
    redirect "txmt://open/?url=file://#{local_file}&line=#{line}"
  else
    not_found
  end
end

Save this as webmate somewhere accessible. If you run webmate while in a directory, it will give you access via HTTP to opening files in that directory. Here’s an example script:

baltika:~ cnixon$ cd Projects/crnixon.org/
baltika:crnixon.org cnixon$ webmate
== Sinatra has taken the stage on port 4567 for development
# Go to the URL http://localhost:4567/content/index.txt:10
127.0.0.1 - - [10/Jul/2008 23:11:38] "GET /content/index.txt:10 HTTP/1.1" 302 - 0.0034

And TextMate opens ~/Projects/crnixon.org/content/index.txt and moves the cursor to line 10.

Colophon

I can’t seem to get along with weblog software. I think that it might be a common trait of programmers; then again, it might just be a trait of someone with my different interests. Most software ends up bothering me because of its constraints. Writing my own always gets me side-tracked on making something bigger and better, and I never finish. I’m web-standards obsessed and love plain text.

This time, I think I’ve found a match. I have the flexibility of writing my own system with the help of having a decent framework behind it. I’m using a static site generator, Webby, along with Textile) and mofo, a Ruby microformat parser. I write posts in Textile, Webby turns them into HTML and updates the front page and archives, and then mofo scans the hAtom tags I’ve embedded in my front page to make an Atom) feed.

For the front end, it’s mainly just me and my minimalist XHTML and CSS. I do have help from Ultraviolet and SenCSS.