Tag Archives: ruby

Render a template from a hash in Ruby

A hash is a great way to manage a list of key/value pairs, and templates are a great way to render content. So here’s a simple way to render a template from a hash. template.erb My favorite color is <%= … Continue reading

Posted in ruby | Tagged , , , , , , , | 1 Comment

extconf.rb:4:in `require’: no such file to load — mkmf (LoadError)

I’ve hit this a dozen times and I always forget the solution. When you get this on Ubuntu, sudo apt-get install ruby-dev

Posted in ruby | Tagged , , , , , , , | 1 Comment

Show Duplicate Filenames with Ruby

Here’s a quick one. I want to show just the names of files that have the same basename in a directory. Code require ‘find’ require ‘set’ all_files  = [] duplicates = {} basenames  = Set.new ARGV.each do |dir|   Find.find … Continue reading

Posted in ruby | Tagged , , , | Leave a comment

Ruby instance_eval gotcha

I don’t know how much of a “gotcha” this is since it’s just a defined behavior and feature of the language, but I still found it a little counterintuitive when I encountered it, and I had to actually read the … Continue reading

Posted in ruby | Tagged , , , , | 1 Comment

Run Sinatra App in a Subdirectory with Rack::Builder.map

Thank god I found Tanner Burson’s blog. I was about to explode. I recommend reading Tanner’s original post, but the short answer is that you want Rack to do some routing for you via Rack::Bundler.map. Here is a super simple … Continue reading

Posted in Sinatra | Tagged , , , , , , , , , , , , , , , | Leave a comment

Request Tracker Watchdog

I recently upgraded from Request Tracker 3.8.0 to 4.0.2 and started running it with FastCGI. Works great except for the odd Bad Gateway message from nginx (still haven’t figured that one out). While v4 makes a lot of improvements over … Continue reading

Posted in scripts | Tagged , , , , , | Leave a comment

Running Rails 2.3.14 on Ruby 1.9.2

While trying to run Rails 2.3.14 on Ruby 1.9.2, I was getting an error page with ActionView::TemplateError (invalid byte sequence in US-ASCII) Turns out Rails 2.3.14 on Ruby 1.9.2 was trying to read my UTF-8 data as US-ASCII. Solution Don’t … Continue reading

Posted in fixes | Tagged , , , , | Leave a comment

Sanitizing File Names with Ruby

At work, I ran into a problem wherein I was copying files from one filesystem (FAT32) to another (NTFS), and there were file names with characters that were legal in the first, but not the second. I wrote a Ruby … Continue reading

Posted in ruby, scripts | Tagged , , , , , | Leave a comment