Category Archives: ruby

Dynamic Class Methods in Ruby

Rails has a whole slew of class methods that really should be instance methods. The most notable of these methods is ActiveModel::Naming‘s model_name, which is a class method that is expected on every ActiveModel object (for example, it is expected by form_for). This code uses that as an example, but the pattern applies anywhere. If […]

`call/cc’ and Self-modifying Code, in Ruby

If you read Matthias Felleisen’s blog post today about using call/cc to write a generator, and you’re anything like me, you must have thought “Ruby has call/cc; how would I do this in Ruby?” This is my first pass. It works, but it could very well be broken, and I know it can have a […]

My Rails Development Environment, version 2: Scribes, Nautilus, and gnome-terminal

On a whim I tried Scribes for a day. It’s not terrible: autosaving, keyword completion, templates, syntax highlighting, and a sleek look. There’s a lot I miss from vim, but after two weeks of Scribes I’m mostly adjusted. (I really, really, really look forward to the autosave misfiring fix.) At first I thought I couldn’t […]

My Rails Development Environment, version 1: vim and screen

Lately I’ve changed the way I manage the code on my Rails projects; this is the overview on how I did it for the past two years. I’ve used vim since my first programming job eight years ago. I’ve use it for email, papers, programming, notes—anything. I instinctively hit escape when I finish typing; my […]

Integer#to_word

The other day some friends and I came across a job posting for ITA Software on the T. It read: If the integers from 1 to 999,999,999 are written as a word, and concatenated, what is the 51 billionth letter? The eight of us spent the duration of the ride discussing this question and its […]

Spider the Web with Ruby

I wrote a Ruby library for crawling the Web. Use it to take down The Man, like so: I used it to gets people’s addresses from around the Web. I plan to put them on a map. I like putting things on maps. It once took obscene amounts of memory, until I discovered that Ruby […]

Ruby Can’t open(‘http://digg.com/’)

This is a bit of a Ruby bug, but it’s so much more of a Digg bug that it’s worth telling the public about: This code, as of Ruby 1.8.5 and March 29th, 2007, will not work. In fact, it will crash Ruby (which I should report, yes). I suspect the crash happens when the […]

Watermarking Photos using Ruby

The task: take a source photo of any size and overlay transparent text atop it. This is useful for asserting to the world that the image is yours (which it sometimes is). Before: After: First, some configurables: For this task I used the GD library. Step one, suck in the image: Step two: overlay the […]

STI and Multiple Databases in Rails

I admit, I believed it when DHH said that Rails apps should communicate via REST if they want access to a shared database. I bought into the hype and even wrote a plugin to make this easier. Well, it’s slow. I don’t have real numbers, of course, because I’m not the type of person to […]

Truncating HTML in Ruby

Update: You should read the comments, then check out the extended verion of truncate_html that uses Tidy. For the blogging Web site we wanted snippets of blog post for the front page and search results. This wasn’t a problem at all for our test blog posts, which we made by pasting lorem ipsum into a […]