Filed under: code

Project Directory Aliasing for Quick Terminal Access

I build a lot of sites for a lot of different clients and have been perfecting my directory structure over the last few years. Because I heavily rely on Terminal to work on projects, I need very fast access requiring little thought to my project directories. At the same time I need projects organized by client so I use this rather obvious structure (these are not my actual clientsI wish!):

Keeping directory names lowercase and avoiding spaces makes for easier tab-completion on terminal.

Even so, typing cd ~/work/rivendell_bicycle_works/rivendell.com (albeit only actually typing cd ~/wo[tab]/riv[tab]/riv[tab]) is too much work when my mind is full of code and I need to get somewhere quick on a new terminal.

Enter aliasing. Aliasing allows me to open a new terminal and type cd riv[tab] and find myself in ~/work/rivendell_bicycle_works/rivendell.com. To facilitate this surprisingly useful ability, I setup an alias at the start of each new project.

When I no longer need quick access to a project, I can just delete the alias to keep my home directly clean(ish).

 

 

From TextMate to Vim

TextMate is a great all-purpose text editor, but it really isn't very good at advanced text manipulation or navigation.  Having dabbled in emacs and its far superior text navigation commands, I found myself getting increasingly frustrated with TextMate's very basic commands. Having to use arrow keys and fully move my right hand away from home row is unacceptable. 

I unsuccessfully tried to switch to emacs. I found it bloated and clunky with awkward configuration and poor defaults, and quickly switched back to TextMate. I finally decided to give vim a try, and was surprised at how decent it was despite the steep learning curve. It has an elegance that emacs seems to lack. After two days of using it on a rails project I made the decision to commit to vim and invest in learning its many motions and commands.

Here are some great resources I used to get started:
  • MacVim - the popular graphical vim for mac
  • PeepOpen - this is the main reason I chose to use MacVim over the terminal vim. If you're coming from TextMate, you'll definitely want the awesome CMD+T shortcut it provides (and if you don't know what I'm talking about, prepare to become addicted)
  • rails.vim - an essential plugin for rails developers
  • snipmate.vim - an excellent snippets plugin that will feel very familiar to TextMate users
  • Color Sampler Pack - a massive collection of excellent themes for vim
  • VI Cheat Sheet - an excellent cheat sheet designed by GoSquared for Smashing Magazine
The two main vim config files are ~/.vimrc and ~/.gvimrc. MacVim will read both, so you'll want to put generic options in .vimrc and options that only apply to a graphical vim (such as the themes linked above) in .gvimrc.

A few learning references I found especially helpful are:

Update: A few excellent vim configuration walkthroughs were posted after this. These two posts are a must for getting your .vimrc in order!

Using Compass with RVM

After installing RVM, Ruby 1.9.1 and setting up a rails 3 Project, I wanted to setup compass.  

Following some advice from http://blog.firsthand.ca/2010/03/getting-rails-30-running-with-stack-on.html I went ahead and added gem "compass", "0.10.0.pre9" to my Gemfile, ran bundle install, did the usual compass --rails . and encountered an unexpected error:

/Library/Ruby/Site/1.8/rubygems.rb:827:in `report_activate_error': Could not find RubyGem chriseppstein-compass (>= 0) (Gem::LoadError)

It seems RVM was somehow relying on my old compass gem I previously used with my system ruby. After trying a few things, I was able to get it working by opening a new terminal, rvm use system, and sudo gem uninstall chriseppstein-compass.  Switching back to my rails project, compass then ran as expected.

 

 

Tiny Sinatra App

In need of a simple text-to-speech web service, I wrote this little script on Sinatra to return an MP3 to the browser.  The TTS is being handled by Festival (which I absolutely would not recommend) and piped to LAME (which is great) for MP3 encoding.

I ended up not using this script in production since Festival's TTS quality is horrible, but it was a fun exercise nonetheless.

I painlessly deployed on Phusion Passenger + Apache with the following config.ru.

Angular

Angular

Interesting new declarative, cloud-based web app platform: <angular/>.  Super simple and easy to get up and running.  Because all the magic happens in JavaScript, you can run your app bits locally (during development) or on someone else's server with zero config.  Looks very useful for on-the-fly data persistence, on client sites in particular.