Log in

Archive for the ‘Ruby’ Category

Oct
13

Old habits die hard. Whenever i upgrade to a new OS i like to do a clean install and OS X Lion was no different1. Everything went smoothly until i tried to install an older version of ruby in RVM (ree 1.8.7). Then the shit hit the fan. After some digging i realized the issues were because Xcode 4.2 only installs LLVM GCC which doesn’t play nicely with some older open source packages. There are a plethora of solutions online simply telling me to set my CC environment variable to /usr/bin/gcc-4.2 except — since i did a clean install and installed Xcode 4.2 as the first version on this machine — i had no non-llvm gcc. The solution after some digging through the homebrew wiki was a stand-alone OS X installer for GCC designed to free developers from the hefty download size of a full Xcode install (and for that brief period where Apple lost its mind and tried to charge for Xcode).

1: For those interested it couldn’t be easier, just follow these instructions from Mashable.

Oct
10

I’ve been using tmux for local development and remote pairing pretty much full-time in the last few months. The ability to create a session in my terminal with all the typical tabs and panes i use for web development, name it, and then just drop it to work on another project is amazing. Switching between projects now takes seconds instead of minutes to reopen tabs. The only issue i’d run into is remembering on which port i hosted the local server; was this project 3001 or 3002? Enter pow. Pow is a simple little monitoring script written by the guys over at 37 Signals to allow you to run named rack servers. It’s as simple as linking your rack app into ~/.pow. For example the following line:

  ln -s ~/Code/MyApp ~/.pow/myapp


provides you with http://myapp.dev as an alias. No more remembering ports! There are a few little issues such as having to touch a specific file (/tmp/restart.txt) to restart the servers but it really does save time despite it.

Oct
23

Wanting to have easy access to all the documentation for my installed gems i decided to setup a startup item for the gem server that comes with RubyGems.

Come to find out the process is incredibly simple. First create a shell script to star the server:

#!/bin/sh
/usr/bin/gem server --daemon

Then create a plist file describing the startup item:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
    <dict>
        <key>Description</key>
        <string>Ruby Gems Server</string>
        <key>OrderPreference</key>
        <string>Late</string>
        <key>Provides</key>
        <array>
                <string>RDoc Server</string>
        </array>
    </dict>
</plist>

Create a folder, i named mine GemServer, and name the shell script the same. Put the script and the plist into this directory and copy it to /Library/StartupItems (you may have to create this).

Or, you could just download the startup item and extract it to /Library/StartupItems.

Restart and point your browser to localhost:8808 and peruse your documentation ’til your heart’s content.

Sep
25
Ruby is easy to read.

When i was first learning Ruby i, like most people, picked up two books. The first was the wonderful pickaxe book; the second, the no-less-wonderful Poignant Guide to Ruby by everyone’s favorite mad scientist – Why the lucky stiff.

When virtually flipping through why’s lovely creation one of the things that caught my eye was a a statement early on in which he simply asked us readers to “read the following aloud to yourself” and followed it with a small block of ruby code:

5.times { print "Odelay!" }

I, being in the comfort of my own home late at night, obeyed and read “five times print odelay!”. I chuckled and moved on. But he persisted asking that i then read another block of code:

exit unless "restaurant".include? "aura"

And once more i obeyed chuckling even more at the concept of a restaurant aura. I’ve often used this as one of the reasons why i love Ruby. When written right it just sort of makes sense. You can read it and understand it more-often-than-not. It’s not the insane business speak like COBOL or the drawn-out run-on sentences of Java, but just simple little statements that do their best to not confuse the reader.

TextMate's Speak Selection option.

Why is all this interesting? Well i was wandering about the bundles menu in TextMate today and stumbled across the ability to Speak Selection. I hastily highlighted a line of the Javascript library i was working on and hit Speak Selection. What i got was something between a three-year-old telling you about their day and a speech synthesizer being circuit bent. I copied in Why’s first example and did the same and was rewarded with “five dot times print Odelay!”. Not exactly how i had read it but still mostly understandable.

So this begs the question: could ‘speakability’ be a viable way to determine if code is understandable? If you can actually read your code aloud – and have it explain in more-or-less english what it is attempting to do – it would seem that there is a much greater chance that the next person to look at your code will be able to interpret it as well.