RubyConf stuff

November 16th, 2007

Well. RubyConf was two weeks ago now and I still haven’t completely wrapped my head around it. It was a different experience this year than last (understanding that last year was my first RubyConf), and I’m not sure whether I liked it better. I would have preferred a single track, although I completely acknowledge the reasons why multitrack made sense… I just didn’t like having to make decisions between two talks I really wanted to see, which happened at pretty much every junction.

I particularly enjoyed Ryan Davis’s and Eric Hodel’s talks, which both more or less boiled down to them talking about the tactics they use to write more/better code. That’s the kind of thing I really like to hear about: the ways that other people boost their productivity and output quality. In this case, the people were experts, but it’s fun to hear from newbies too, as they almost always bring new perspective.

Another highlight was Laurent Sansonetti’s talk on how Apple loves Ruby. I can’t really explain how totally awesome this was. Apple really does love Ruby, and the stuff you can do in Leopard with Ruby is astounding. You’ll just have to watch the video.

Speaking of which, one totally awesome thing that may not be universally known is that Confreaks recorded (almost) every session and are publishing the videos on their website. It’s a lot of video to process so things are a little slow in coming, but eventually all of the conference videos will be here. They’ve already published all of the RejectConf presentations... you can see my 3 minutes on IRB history (now with more working) here. The code is available here.

I’ve also arranged to get the raw camera captures for my talk and I’ll be putting together a video of my presentation in a different format later. On that topic, the slides for my presentation are available at this link. They’re under the Creative Commons Attribution-Noncommercial-Share Alike 3.0... the video on Confreaks will be as well, which is slightly different than what their pages say. The non-commercial clause is the only exception.

Also as promised, below is a list of links to the stuff I talked about:

Serial Hardware

  • Keyspan USA-19HS USB -> serial adapter — the best USB/serial adapter I’ve found. About $40.
  • FTDI FT232R USB -> UART chip — These are only available in surface-mount packaging. You can get one on a breakout board from Sparkfun, if you need it by itself. See the Buy Some Gear section.
  • FTDI TTL232R USB -> UART cables — these are USB cables with embedded FT232Rs, available in various configurations. Necessary if you’re using a Boarduino (see below) and handy to have around for other purposes as well.

X10 Home Automation

  • x10-cm17a gem / project page
  • CM17A FireCracker kit — The FireCracker control module, one appliance module, one transceiver/lamp module, and a remote. Note that these are much cheaper on eBay. See links in the Buy Some Gear section below.

BetaBrite LED sign

Arduino development boards

XBee Radios

  • other xbee modules are pin-compatible, so pick the one that best suits your need, and remember that the Series 1 doesn’t fully support ZigBee
  • Arduino xbee shield

Buy some gear!

  • Keyspan USA-19HS — Froogle it or just hit up your local computer store. I got mine at CompUSA.
  • FTDI FT232R — Available on a breakout board from Sparkfun, or from Digi-Key and Mouser as a bare part.
  • FTDI TTL232R — Available in all configurations direct from FTDI, or in most configurations from Digi-Key and Mouser. If you’re doing a Boarduino, though, your best bet is Adafruit, because you can get a little price break if you get it bundled…
  • X10 gear — eBay. Try this search for “x10 firecracker”.
  • BetaBrite — Apparently they’re sold at Sam’s Club. We don’t have those in Oregon so I can’t confirm. I got mine from eBay. I use this search, which catches both “BetaBrite” and “Beta Brite”. You may be able to find other retailers too.
  • Arduino — Lots of options here. Sparkfun is a good one, but I prefer Adafruit. I recommend the Starter Pack, which comes with an Arduino, ProtoShield kit, battery, wall wart, USB cable, and some goodies to play with.
  • BoarduinoAdafruit. Be sure to tick the box to add the TTL232 cable if you need one. You’re going to have to solder this one… if you just don’t feel like it, email me and we can talk ;)
  • ProtoshieldAdafruit again. There’s also the Sparkfun one, but it’s more expensive and poorly designed (see the last paragraph in the description on Sparkfun to see what I mean)
  • XBee modulesDigi-Key or Mouser. Maybe other places too, but they’re who I’ve used.
  • XBee ShieldNKC Electronics, who sells on eBay as nkc_store. I’ve been very pleased with their service. NKC also sells some Arduino clones, for what it’s worth. Sparkfun sells exactly the same thing (albeit with an XBee module) for $80, which is highway robbery. Here’s the link, though, if you feel like throwing your money away :)

RubyConf 2007

October 8th, 2007

So the big (to me) announcement: I’ve been invited to speak at RubyConf 2007 next month! My presentation is called “Controlling Electronics with Ruby”, and you can read the proposal here. It’s going to be fun; I’ll be bringing along some hardware to demonstrate with :)

Also, for my own benefit I put together a calendar of the RubyConf sessions. It’s available here, feel free to grab it. You can probably subscribe to it using iCal or whatever, and if there are changes in the agenda, I’ll update it. It should contain timezones for everything, but I might have missed one or two, so please let me know if it’s wacky for you.

That’s all. See you in Charlotte!

On behalf of the entire LAIKA Information Technology department, it is my great pleasure to announce the release of a number of projects developed by the Information Systems group:

  • Athenaeum — A “live” web view of the contents of a Delicious Library
  • Growl Notifier — A plugin for CruiseControl.rb that sends build notifications to one or more Growl daemons.
  • Linen — A framework for building command-line interfaces
  • TextMate Bundle — Some of us use TextMate. This bundle includes some helpful commands and snippets that we wrote.
  • ThingFish — A network-accessable datastore with extensible metadata
    Please note that the ThingFish release is alpha quality, and much has changed between the current download and trunk. Watch for a new release Real Soon™

These projects were all developed to fit needs within our organization, but designed to be useful outside LAIKA as well. They’re released under the BSD license, and are therefore free to use, in every sense of the word.

Where To Get It

The primary source for LAIKA Open Source software is opensource.laika.com. This is a Trac instance, and is the main point of contact for all LAIKA open source projects. Check here first. File bugs here. Read documentation here :)

Downloads will also be hosted at RubyForge, so any of our projects that are available as gems will be installable via the normal gem mechanism. You can view our project page at laika.rubyforge.org and download our files at here.

About LAIKA

LAIKA is an animation studio based in Portland, Oregon (USA). We are currently working on two feature films and a large number of commercial projects. More information is available at laika.com

About LAIKA IS

LAIKA’s Information Systems group is a team of programmers, database administrators, and tech writers inside the Information Technology department. We make the shiny tools that help the rest of LAIKA do their jobs more easily, ease the sharing of information between groups, and solve mission-critical problems (like picking a place to go to lunch).

We believe in open source software. Many of the tools we use in-house are open source, and we feel strongly that we should give back whenever possible.

LAIKA’s IS department is:

  • Ben Bleything
  • Jeff Davis
  • Michael Granger
  • Steven J. Hall
  • Jeremiah Jordan
  • Myra Lavenue
  • Mahlon E. Smith
  • Anthony Roberts
  • Kim Wallmark

How to Contact Us

If you’ve got problems with the code, please file appropriate bugs in our Trac instance. If you’ve got general questions or comments, please email opensource AT laika, dot com.

Astute readers will recall that during RubyConf last year, I posted about a little irb hack I’d written that allowed for shell-style history viewing and replay. There was a problem with it, however… replayed lines that made assignments didn’t work. So if you tried to replay

1
2
3
4
>> b = 5
=> 5
>> b + 10
=> 15

... you’d get …

NameError: undefined local variable or method `b' for main:Object
        from (irb):1

... which sucks. This has now been fixed! Witness:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
>> b = 5
=> 5
>> b + 10
=> 15
>>  exit

superx ~...personal/toys/irbhistory > irb
>> h
[0937] b = 5
[0938] b + 10
[0939] h
=> nil
>> h! 937,938
=> 15

So that’s pretty cool, yeah? You can get the updated code here. It’s also in subversion, here.

Thanks to Giles Bowkett for pointing out a mis-feature that resulted in all evals returning nil, when you’d probably want them to return in the usual way. This is fixed now :)

Once again, PDX.rb will be hosting an evening of wide-ranging talks about Ruby. This year the focus is on people doing strange things with Ruby. Strange, of course, is anything that’s just a little bit outside the usual. If you’ve created a new Ruby-based interface for hacking on your brand-new internet-enabled phone (rPhone anyone?) or composed your latest bit of metaprogramming magic, we’d love to hear about it.

We’ll be keeping the event open-ended and freeform. We’ll use the lightning-talk-inspired approach and give each presenter the opportunity to cram whatever they can into 10 minutes. Make it interesting and you might even get an extra minute or two. We’ve already selected 7 speakers, but there will be a few slots left open until the actual event.

Our speakers are:

  • Greg Borenstein — programming Arduino boards with Ruby
  • Lennon Day-Reynolds — Speaker’s Discretion
  • Giles Bowkett — Creating programmatic MIDI music with Ruby
  • John Lam — Running Ruby on the CLR
  • Ola Bini — JRuby!
  • Ian Dees — Radical Test Portability
  • Luke Kanies — Using Racc to write a real Domain Specific Language
  • You
  • ... or possibly… YOU

This is all taking place Tuesday, July 24th (hey, that’s today!) at 7:30 pm. The location is Holocene (map), here in beautiful Portland, Oregon.

There will be plenty of Ruby fun going on and lots of socializing with fellow Rubyists. Last year, FOSCON II was overflowing. We’ve found a new venue to fit you all in, so why miss it? Oh yeah, did I mention the free pizza?

Fun with hpricot

May 15th, 2007

Those who know me personally know that I’m a pretty huge video game nerd. I’ve been wanting to learn hpricot better, so I decided to combine the two interests. I give you vgdod.rb, which goes and scrapes info about Amazon Video Games’ Deal of the Day. It could probably be optimized, and the XPath could likely be better, but it gets the job done!

It was interesting to try to write XPath for HTML that I didn’t control… this was the first time I’ve had that particular joy, and it was a good exercise. I think we (web developers, that is) sometimes forget that other people might want to manipulate our HTML at some point. Anyway, the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/env ruby

%w(rubygems hpricot open-uri shorturl).each {|g| require g}
def fetch(url = '') ; return Hpricot(open("http://www.amazon.com" + url)) ; end

vg_url = fetch.at("a[text()=Video Games]")[:href]
dotd_img = fetch(vg_url).search("img").select {|e| e[:src] =~ /deal-of-the-day/}.first
dotd = fetch(dotd_img.parent[:href])

# title -- platform -- price -- url
printf "%s -- %s -- %s -- %s",
  dotd.at("//div.buying//b.sans").inner_text.strip,
  dotd.search("//b.price").last.inner_text.strip,
  dotd.search("//div[@class=buying]")[3].inner_text.gsub(/(\ |\s|Platform:)/, ''),
  WWW::ShortURL.shorten("http://www.amazon.com#{dotd_img.parent[:href]}")

I have been getting absolutely slammed with stupid drug spam. Mephisto’s spam moderation stuff is pretty good, but the sheer volume required me to go down to the console to take care of the problem:

1
2
3
4
5
regex = /viagra|cialis|xanax|levitra|tramidol|valium|\
carisoprodol|tramadol|nexium|ultracet|allegra|\
zoloft|hoodia|snitz|ultram|levaquin|augmentin|\
prednisone|phentermine|fioricet|diethyproprion/i
Comment.find_all.select {|c| c.body =~ regex}.map(&:destroy).size

I was building the regex as I went along so I don’t have an exact count, but that probably deleted 500 comments. Much easier to moderate the other crap now.

Rails Cookbook

January 23rd, 2007

Hello intertubes. Long time, no type!!!

I know that back in December I’d have some news to post soon. This is not that news, but it’s news of a different type! The Rails Cookbook* is shipping, a fact that no doubt everyone reading this already knew.

What you might not know is that it contains three recipes written by yours truly. If you pick up a copy, look for these recipes:

  • Deploying with Capistrano When You Cannot Access Your SCM
  • Deploying Your Application To Multiple Environments with Capistrano
  • Increasing Performance by Caching Post-Processed Content

I should point out that the “can’t access SCM” uses code that’s based on Jim Morris’s work here. I thought I had mentioned that in the recipe itself, but it’s not in my review copy. Jim, if you’re reading this, I apologize for not giving you the credit due.

My experience with the topics covered in all three recipes came from real problems that I dealt with during my time at EDGE Design. If there is interest, I can talk in more detail about the problems and solutions.

I reviewed the book as well, and there’s some really cool stuff in there. It’s up through Rails 1.2, so if (like me) you like to learn from a cookbook-style thing, it’d be a good option to get caught up with the new stuff going on in Rails. Check it out!

* yes, that’s an affiliate link

Tracing method execution

December 11th, 2006

Update: tweaked the Proc to trace returns by default as well, and tell you what kind of call happened. Also tweaked the order of fields.

Just a quick little snippet to make up for my extended absence. This is probably old news to a lot of readers, but someone should get some value out of this.

Sometimes, you need to trace execution through your script. In my case, I’m debugging some tweaks to ActiveRecord::Migration and something is getting hosed along the way. Kernel#set_trace_func to the rescue!

Drop the following in your .irbrc, fire up irb, call enable_trace, and then whatever you’re trying to do:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

def enable_trace( event_regex = /^(call|return)/, class_regex = /IRB|Wirble|RubyLex|RubyToken/ )
  puts "Enabling method tracing with event regex #{event_regex.inspect} and class exclusion regex #{class_regex.inspect}"

  set_trace_func Proc.new{|event, file, line, id, binding, classname|
    printf "[%8s] %30s %30s (%s:%-2d)\n", event, id, classname, file, line if
      event          =~ event_regex and
      classname.to_s !~ class_regex
  }
  return
end

def disable_trace
  puts "Disabling method tracing"

  set_trace_func nil
end

For bonus points, you can pass in alternate regexes depending on what you want to capture. Out of the box, it’ll only show you Ruby method calls, and will exclude anything that comes from a class matched by the class_regex parameter. Check out


ri Kernel#set_trace_func

for more details about what you can get/do.