Excon: a sane alternative to Net::HTTP

Here’s how I use Net::HTTP:

# It rubs the lotion on its skin. It does this whenever it's told.
url = URI.parse('http://www.google.com/')

# It rubs the lotion on its skin or else it gets the hose again.
# Ruff! Yes it will, precious, it will get the hose.
File.open('result.txt', 'w') {|f|

  # It places the lotion in the basket.
  res = Net::HTTP.start(url.host, url.port) {|http|

    # Now it places the lotion in the basket.
    http.get('/') do |str|

      # PUT THE FUCKING LOTION IN THE BASKET!
      f.write str
    end
  }
}

Excon is a pleasant alternative to Net::HTTP written by Wesley Beary (@geemus). It has a simple API:

# get
Excon.get("http://localhost:4567/").body

# get with headers
Excon.get(
  "http://localhost:4567/",
  :headers => {"User-Agent", "Excon"})

# get chunked
Excon.get("http://localhost:4567/") do |chuck|
  puts chunk
end

# keep-alive
@connection = Excon.new("http://localhost:4567")
@connection.request(:method => "GET", :path => "/foo")
@connection.request(:method => "GET", :path => "/bar")

Mocking is built in:

Excon.mock = true

# any request returns Hello
Excon.stub({}, {:body => "Hello"})

# be more specific about the request
Excon.stub({:path => "/foo"}, {:body => "Foo"})

Though it doesn’t support posting form data from a simple hash or multipart file uploads:

puts Excon.post("http://localhost:4567/", :body => "foo=bar&wam=bam")

I haven’t benchmarked anything, but it has performed well for me. Also, it’s compatible with Windows out of the box, an issue with curb.

Give it a try.

RubyNation Recap

I enjoyed RubyNation this year. The small size makes it easier to get to know both local developers and bigger names in the Ruby community.

A highlight for me was @geemus’s talk on Fog, a high level API for deploying to a good number of cloud services like Amazon and Rackspace. I’m super late to the cloud game, but it seems we could take some pain out of managing our QA and stage environments at Razoo by deploying them to the cloud. Phrases like “deploying to the cloud” are grinding my nerves though.

Another highlight was the Ruby for Kids session. 10 kids joined volunteers from the conference, including yours truly, to hack on a game they’ve been building with gosu. These kids are 10 to 14 years old and using Macs, TextMate, Terminal, Git, and Ruby! If we can avoid destroying the planet, the future is certainly bright.

shooter

As with every conference, I was inspired by the creative energy. I’m going to update my illustrious croc gem, which is useless now that RVM is standard operating procedure.

Making RVM work with Zsh and Vim

I’m not going to say how long it took me to figure this out. I wanted RVM to work with Zsh and Vim. But when I ran ruby commands with :! or :sh, it would always use the system ruby, not the ruby I had selected with RVM.

Here’s what finally worked:

  1. I added SHELL=/bin/zsh and [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" to ~/.zshrc
  2. I commented out the path_helper stuff in /etc/zshenv

This makes Vim run zsh instead of bash when running shell commands and prevents Apple’s path_helper utility from rearranging PATH when zsh is run.

How I'm Doing Inbox Zero

I’m a Gmail user. I used to carefully label any email I wanted to keep, using labels for each project. This kept my inbox clear if I did this frequently throughout the day. But if I got lazy or was returning from a long weekend, messages piled up and labeling became dreadful. Labels were helpful in finding a message if I wasn’t sure what I was looking for, but otherwise provided little value.

I’ve ditched the labels.  As I go through my inbox, I deal with each message this way:

  1. If it’s not worth keeping, I delete it.
  2. If it’s worth keeping, but I don’t need to act on it, I archive it.
  3. If it’s something I need to act on, I label it TODO.

The decision is simple and gets the inbox cleared quickly. I work through the TODO list, moving them to DONE when I’ve finished with them. It works out that when I need to refer to a message, I can find it quickly in TODO or DONE.

If a message sits in TODO for a long time, but I can’t bring myself to archive it, I move it to DEFER. It’s kind of pointless because I typically don’t do anything with these messages and they eventually get archived.

So far so good. I spend less time managing my inbox, I rarely miss important messages and I can find what I’m looking for quickly.