giant robots smashing into other giant robots

Written by thoughtbot

jasonmorrisontb

Bring your laptop, get started with Ruby at Tuesday’s Boston.rb meetup

Well, howdy there!

Interested in Ruby?

Have you been…

…interested in building web application, but aren’t sure where to start? We’ve all been beginners once, so let us lend a hand!

…seeking a technical co-founder, but finding it difficult? Investing the time to learn programming will do wonders. You’ll be better equipped to sniff out quality developers, and quite possibly knock out a prototype on your own.

…teaching yourself Ruby or self-studying on Rails and running into questions? Rubber Ducking can help, but it’s not nearly as much fun as meeting your fellow Boston Rubyists.

…programming Ruby or Rails for a little while (or a long while) and are looking to help teach and welcome new folks to the community?

Let’s meet up!

Drop by the thoughtbot office this Tuesday, October 4, at 7pm. We’ll be hosting a structured session on getting your laptop set up for Ruby development. We’ll be following the process described here and be available for debugging:

2011 Rubyist’s guide to a Mac OS X development environment

Please RSVP to the event so we know how much food and how many drinks to get. We’re happy to field questions ahead of time in the comments below, or you can sign up for the Boston Ruby mailing list, mosey over to the email thread for this meetup, and say hello!

dancroak

2011 Rubyist’s guide to a Mac OS X development environment

It’s been two and a half years since my last laptop. It’s neat to look back and see how much has improved since then for setting up a Ruby development environment.

Of particular note, Homebrew, RVM, and Bundler did not exist back then.

Here’s how I set up an OS X 10.7 (Lion) thoughtbot laptop in 2011.

GCC

I need GCC to help install everything else so I downloaded GCC for Lion.

We used to have to install XCode to get GCC when OS X wasn’t for developers, which was a 3-4GB download and took 10GB+ of space. Buzzkill.

However, Kenneth Reitz, one of the Readability guys, fixed this with his OS X GCC installer, which is a comparatively svelte 272MB download.

Later on, when we’re installing things using Homebrew, we’ll see warnings like:

Xcode is not installed! Builds may fail!

But, the builds will build fine.

While that’s installing, we’ll customize our environment a little.

SSH

I need a public key to get access to private Github repositories.

ssh-keygen -t rsa

I’m kept hitting “enter” until it was done. Alternatively, I could have brought my old SSH key over but I’m not into falconry.

dotfiles

We have a standard set of configurations for vim, irb, git, zsh, and more.

I cloned the repo:

git clone git://github.com/thoughtbot/dotfiles.git

I ran the installer:

./install.sh

This sets up the appropriate symlinks (~/.vimrc, ~/.irbrc, etc.). I’ll stay up-to-date and contribute using the fork-track-update flow described in the README.

zsh

Our dotfiles assume zsh so I switched from the bash default to zsh:

chsh -s /bin/zsh

Re-map Caps Lock to Control

We’re pretty much all vim users here so it’s nice having super-quick home-row access to the Control key… and who uses Caps Lock, anyway?

System Preferences > Keyboard > Modifier Keys

git

Already installed by default, but I set the global config:

git config --global user.name "Your Name"
git config --global user.email you@example.com

Heroku accounts

I’m using Heroku for all my apps right now. However, thoughtbot’s clients and even our own apps like Trajectory are not owned by my Heroku account. So, it comes in handy to be able to switch to a different account on a project basis.

heroku plugins:install git://github.com/ddollar/heroku-accounts.git
heroku accounts:add dan  --auto
heroku accounts:add thoughtbot  --auto
heroku accounts:add client  --auto
heroku accounts:default dan

thoughtbot’s laptop script

Once GCC is downloaded and installed, I’m ready for the heavy-duty installation using our laptop script.

bash < <(curl -s https://raw.github.com/thoughtbot/laptop/master/mac)

This installs:

  • Homebrew (for managing operating system libraries)
  • Postgres (for storing relational data)
  • Redis (for storing key-value data)
  • Ack (for finding things in files)
  • Tmux (for saving project state and switching between projects)
  • ImageMagick (for cropping and resizing images)
  • RVM (for managing versions of the Ruby programming language)
  • Ruby 1.9.2 stable (for writing general-purpose code)
  • Bundler gem (for managing Ruby libraries)
  • Rails gem (for writing web applications)
  • Heroku gem (for interacting with the Heroku API)
  • Taps gem (for pushing and pulling SQL databases between environments)
  • Postgres gem (for making Ruby talk to SQL databases)

It took about 15 minutes for everything to install.

While it’s running, it copies your SSH key to the clipboard and opens your Github SSH page. Paste your SSH key so your Github account is authenticated to your machine.

Caveats

We wrote a laptop script because we help hundreds of people a year get a Ruby development environment set up at workshops and Boston Ruby hackfests. One time we set up 30 business school students’ laptops in 3 hours.

If you read our source, you’ll see it it’s very simple but more invasive than, say, the excellent Cinderella by Corey Donohoe, which uses Chef to keep your machine tidy. We’re assuming the person definitely wants a “thoughtbot laptop”.

DIY

It’s pretty easy to write a wrapper that installs Homebrew, RVM, and your favorite databases and gems so consider forking our project and writing your own script, just like you might write your own Rails template script like Suspenders.

jyurek

Hiding Visor

An excellent little plugin, Visor is. You can have a Quake-style console that pops up whenever you want, in any app. Only trouble is that I wanted to be able to close Terminal.app and still have the Visor accessible. I found these directions linked off the Visor wiki to get rid of Terminal.app from the process list, which is a set in the right direction, but not perfect. There were some quirks that made the experience… iffy.

Here’s how to get Visor as it’s own, invisible, app, and still keep Terminal.app around like it always has been:

  1. Get SIMBL
  2. Get Visor
  3. Optionally, get TerminalColors, because the default blue in Terminal.app is horrible
  4. Install each.
  5. Make a copy of Terminal.app (I called mine VisorTerminal.app)
  6. Right click on it and “Show Package Contents”
  7. Open Contents/Info.plist with the Property List Editor
  8. Change CFBundleIdentifier from “com.apple.Terminal” to “com.apple.VisorTerminal”
  9. Add the key LSUIElement with a value of 0
  10. Save
  11. Find the Visor and TerminalColors plugins (they should be in /Library/Application Support/SIMBL/Plugins)
  12. Open Visor’s Info.plist (Right-click > “Show Package Contents” > Contents > Info.plist)
  13. Change the “SIMBLTargetApplications/0/BundleIdentifier” value to “com.apple.VisorTerminal” and Save
  14. Open the Info.plist for TerminalColors (same as above)
  15. Select “SIMBLTargetApplications” and click “New Child”, change the type to Dictionary
  16. Add new children so that the keys and values mimic the existing one
  17. Make sure that one BundleIdentifier is com.apple.Terminal and the other is com.apple.VisorTerminal, and Save
  18. Get this app, unzip it and put it wherever you’d like (I have mine in /Applications/Utilities).
  19. Open Script Editor
  20. Open the VisorStarter app in the Script Editor
  21. Change “Terminal” to “VisorTerminal”
  22. Save
  23. Add VisorStarter to your startup items

Ok! That takes care of that. It’s a bit more involved than the other instructions, but will completely separate Terminal and the Visor. Trouble is, they’re completely separate. You’ll have to set up the fonts and colors all over again, but it shouldn’t be that big a problem. If you have trouble getting the window settings to appear, open the Visor preferences from the Visor menu and the Window Settings should come right along. And the best part is that if everything worked correctly (you may need to log out and back in or reboot) the ANSI Colors option should still be in both Terminal’s and Visor’s settings.

jyurek

BBEdit “Projects” in Applescript

I really, really can’t decide between TextMate and BBEdit, the majority of reasons of which I should leave for another post. But anyway, one of the most annoying things that I thought was left out of BBEdit was the ability to save the contents of the Documents Drawer for easy retrieval. I like to keep my work logically separated by window, and it’s a pain to drag all the documents I need where I want them every time.

Thanks to BBEdit being very Applescriptable, I wrote these scripts. Stick ‘em in your scripts folder and they’ll get some use.

Save Project

tell application "BBEdit" 
    set w to first text window
    set theFiles to the file of every item ¬
        of text documents of w
    set f to choose file name with prompt ¬
        "Select a project file." 
    try
        set fSpec to open for access f ¬
            with write permission
    on error what
        display alert ¬
            "Could not save project." message what
        close access f
        return
    end try
    set eof of fSpec to 0
    try
        write theFiles to fSpec as list
    on error what
        close access f
        display alert ¬
            "Could not write project file." message what
        return
    end try
    close access fSpec
end tell

Load Project

tell application "BBEdit" 
    set f to choose file
    open for access f
    set fs to read f as list
    close access f

    set w to make new text window
    set show documents drawer of w to true
    set doc to ID of first text document of w
    set i to 1
    open fs opening in w
    close document id doc
end tell

It’s not gorgeous code, but it works. And it’s one less thing I have to worry about in BBEdit. Interestingly enough, I would have written these in Ruby with RubyOSA, but the darn thing won’t load BBEdit’s sdef because it uses non ASCII characters.

And for what it’s worth, I like to save the documents with a .bbdd extension.