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 better [...]
Category Archives: ruby
`call/cc’ and Self-modifying Code, in Ruby
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 do [...]
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 blog [...]
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 solutions. This [...]
Spider the Web with Ruby
I wrote a Ruby library for crawling the Web. Use it to take down The Man, like so:
require ‘rubygems’
require ’spider’
include Spider
spider(['http://del.icio.us/mikeburns']) do |a_url, a_web_page|
puts "I am taking down The Man by knowing this URL: #{a_url}"
end
I used it to gets people’s addresses from around the Web. I plan to put them on a map. I [...]
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).
require ‘open-uri’
open(‘http://digg.com/robots.txt’)
I suspect the crash happens when the timeout [...]
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:
IMAGE_FILE_NAME = ‘/usr/home/mike/pictures/c4rt.jpg’
OVERLAY_FONT = ‘/usr/X11R6/lib/X11/fontsbitstream-vera/Vera.ttf’
OVERLAY_ANGLE = 1
OVERLAY_STRING = "Copyright #{Date.today.year} Mike Burns"
For this task I used the GD library. [...]
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 write [...]
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 text [...]
Curly vs. Do/End
Ruby discovery for today: curly braces have a different precedence than do/end. That is, these two expressions mean different things:
user.houses.map { |h| h.verified = false if h.hide_avm?; h }.to_xml
user.houses.map do |h| h.verified = false if h.hide_avm?; h end.to_xml
I’m still unsure what the second one means, but I do know that it doesn’t work.