?

Log in

No account? Create an account
wshaffer
Adventures in Ruby 
24th-Feb-2013 02:32 pm
mini-me
A couple of months ago, I started learning to program in Ruby. Largely because I somehow stumbled across Brian Marick's book, Everyday Scripting with Ruby, which poses the questions: "Do you spend too much of your working life copying and pasting or otherwise manually manipulating data? Wouldn't you like to be able to get a computer to do that for you?" To which I answered, "Yes!"

So, I've been slowly working my way through Marick's book, and playing around with ruby koans, and reading bits of why's poignant guide to ruby, which has got to be one of the most extraordinary pieces of technical writing ever committed.

And I've written some little toy scripts, but today I wrote my very first properly useful script. To give a bit of background: For FOGcon, we keep the code for our website backend in a source code repository called Github. We use Github, among other things, to track the bugs and issues that people report in using the database. And one of the things I periodically have to do is get information about issues out of Github and pass it on to people who don't have Github accounts and so don't have the ability to access our issues tracker directly. Up until today, I have been doing this by clicking around in Github and copying and pasting.

But today, I thought, "I should be able to script this." And lo and behold, with a bit of tinkering, I now have a script that logs into Github, downloads all the open issues in a given milestone, and prints out the issue number, title, and description for each one.

Interestingly, the breakdown of how I developed the script went something like this:
~30 minutes: Determining that there is a Github API, that a suitable Ruby wrapper for the API exists, and researching whether this wrapper can access the information I want.
~1 hour 30 minutes: Installing various necessary Ruby 'gems' (a.k.a libraries) and dinking around trying to resolve various dependency issues.
15 minutes: Writing and testing the script.

This was pretty much tinker toy programming, in that the Octokit Ruby library that I used did all the hard work. All I had to know was how to do some basic operations on an array, and how to print out the information. The entire script is 13 lines long.

So, yeah, this decision to learn a bit of Ruby scripting seems to be paying off.
Comments 
25th-Feb-2013 01:44 am (UTC)
sweeet! do you know angelbob? he is a king of Ruby and a good teacher and encourager...
25th-Feb-2013 06:50 am (UTC)
I don't think I've had the pleasure of meeting angelbob, but I had a look at his book on Ruby, and it looks incredibly awesome. (Also way way too advanced for me at the moment, but something to look forward to if I decide to take my skills beyond simple scripting.)
25th-Feb-2013 03:01 am (UTC)
Cool!

I'm not sure how much sysadmin-type stuff you do already, but since you're starting out with Ruby, I feel compelled to mention a Ruby cheat code: if at all possible, do your work on an up-to-date Debian or Ubuntu system and use the packages that come with the OS. Gems, like CPAN and pypi and all those other things, is a rich library of packages but also a dependency hell waiting to happen because it was written more like a build system than like a package manager. Debian does a really good job of maintaining the packages so you can just install them with apt-get like you install anything else, and Ubuntu does a good job of letting you run an up-to-date Debian system (tracking the "unstable" distribution) without getting broken packages.
25th-Feb-2013 07:00 am (UTC)
That actually sounds like a good tip - I've been doing most of my Ruby stuff on my home desktop system, which is running Mac OS X, and that was partly the source of some of my dependency woes. I will probably find myself at some point wanting to write a script that has to run on Mac or Windows, but using an Ubuntu system as my default for would be easy enough.
This page was loaded Sep 22nd 2017, 7:13 pm GMT.