git stash apply syntax

February 28th, 2008

It took me a few tries to figure out how ‘git stash apply’ can apply a specific stash. The trick is you have to use the stash{@X} as listed in git stash list, not the string you gave it.

So if git stash list has

bcooke@cc $ git stash list
stash@{0}: On local-trunk: names changed to protect w/ correct files
stash@{1}: On local-trunk: the innocent
stash@{2}: On local-trunk: background that thing

To apply the stash named “background that thing” I just have to run

git stash apply stash@{2}

and all is well.

Aliasing http://localhost

January 11th, 2008

When working on multiple rails apps I’ve been annoyed that the URL field in the browser gets cluttered during autocomplete. My autocomplete for http://localhost:3000/ will have paths for each app I’ve worked on recently. Since the browser just sees them all as http://localhost:3000 it returs all the matches. Same problem for form auto-complete and 1password auto-complete.

There’s an easy way around this.

on a Mac or other *nix

Edit /etc/hosts and add one line per project. Here’s my /etc/hosts:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
127.0.0.1 cc
127.0.0.1 mlk
127.0.0.1 si

255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0     localhost

cc, si and mlk are abbreviations for sites I’m currently working on. With this in place I continue to start rails as ./script/server and it listens on localhost port 3000. But now when I’m working on ‘cc’ I point my browser at http://cc:3000. This makes it such that all autocompletes are now only for the ‘cc’ app. I find it a great benefit for such little effort.

Windows

Updated 1/12/07

Andy Kim commented that the windows hosts file is at C:\WINDOWS\System32\Drivers\etc\hosts

mybizexpenses.com is mentioned in the latest entry of the always educational, “The Rails Way”. Jamis points out how I should be using named callbacks and a simple way to make a confusing function, well, not confusing.

The article is pretty short, but very handy. I didn’t know named callbacks existed.

I really love how much a lot of the high profile rails folks give back to the community via things like this.

I have an automator workflow that I’ve been using that others might find useful. It’s heavily based off of the web20show’s own script (original here). The biggest difference (if I remember right) is my flow takes the project directory as an argument vs. asking for it. It opens 3 iTerm tabs. 1 running ./script/server, 1 running autotest and 1 just sitting in your projects directory. localhost:3000 is then opened in your default browser (usually before the web server is ready) and TextMate is opened with the interesting directories loaded in (does not open ‘logs’ or ‘vendor’ or stuff like that).

For a long time I ran this as a Finder plugin. That required finding the project in Finder, right clicking on it and saying Automator -> RailsWork. Lately I’ve switched over to having the workflow be a .app and opening my project folder with that .app via QuickSilver.

I have a 48 second screencast of that in action. And of course, the workflow is available too: RailsWork.workflow.zip

update about requirements: The workflow uses TextMate, iTerm and requires TextMate be setup with its ‘mate’ command described here.

Screencasts Galore!

March 28th, 2007

I’m a peepcode fan. For $9 you get a great, in depth tutorial on whatever the topic might be.

A week or two ago I learned about railscasts. These are just as pro as the for pay peepcodes, but they’re free. The big difference being the railscasts are very short. Often less than 5 minutes. Ryan picks something small to cover, and covers it well. Most of the time the topic is fairly novice, but I’d be lying if I said I didn’t learn anything.

I’ve been using http://uptime.openacs.org to monitor a static site for a while now. Not long ago I realized it could be used to monitor a rails app too. To do this, you have to:

  1. create an action who’s result simply outputs ‘success’
  2. make sure you can get to that action via a route.

Deploy that and point the uptime servers at it and you’re good to go. You can get fancy by making the new ‘success’ action return an error if it can’t do a simple ActiveRecord query or something similar. Make it test whatever you care about. And all this for free.

update: I created a plugin that creates a generator to generate a controller and a route as described above. Available here.