cat /dev/brain

A Few Thoughts

I've just had a few things kicking around in my head lately and I thought I'd jot them down.

github3.py

With the exception of paginated calls, github3.py is essentially feature complete but is lacking tests for everything. My plan as of this point in time is to finish writing tests for it and then work on paginating certain calls. Luckily, Kenneth Reitz just released requests v0.13.8 which parses link headers automatically. This makes my life easier. Had Rhys Elmore not contributed the patch, I probably would have worked on it. This brings me to the next thing I've been thinking about.

requests

I made my first significant (in my opinion) contribution to an open source project this past weekend when Kenneth Reitz accepted my work on accepting lists of key-value tuples where only dictionaries were previously accepted. I haven't completed it fully yet, but those changes were included in requests v0.13.7. I have made small-ish contributions elsewhere and of course made my own projects, but this was important to me. I no longer feel like a total leech on the open source community.

Learning Ruby

I was a bit bored this weekend as well and I follow Gary Bernhardt on twitter. He (if I remember correctly) tweeted a blog post by Zed Shaw about how programming languages have social mores and calling them idioms isn't correct. His example of .each in Ruby was intriguing to me. I've browsed ruby code and been able to generally understand it without too much trouble, so I decided to see how difficult to pick it up it would be and lucky for me Zed Shaw wrote Learn Ruby the Hard Way. In an hour or less I had already reached example 12. I ran the example after substituting 'http://httpbin.org' for 'http://ruby-lang.org/en' (httpbin is another of Kenneth Reitz's creations) and I noticed that each line was quoted. Given the line which I knew produced this:

open('http://httpbin.org/') do |f|
    f.each_line {|line| p line}
    # etc.
end

I was concerned with the magic that caused this. Honestly, it bothered me as much as some of the magic in perl does, so I knew I could reproduce the behavior. First I knew that each line had to end with a newline so that had to be removed. Luckily string objects in ruby seem have the function chomp like the builtin function in perl. And with what little ruby I knew, I did:

open('http://httpbin.org/') do |f|
    for line in f.each_line
        puts "\"#{line.chomp}\""
    end
    # etc.
end

I'm still trying, however, to determine how exactly those three lines equate to that one. I'm still learning ruby though, so I suspect I'll learn it soon, but the fact that I can not do anything like that in python (and will never encounter something like that) is one reason I already like python better. I will say that I like how ruby has the ability to make opening a URL behave like a file (with open-uri); that impressed me.