Entries Tagged as 'ruby'

Friday, October 5th, 2007

Reading An Excel File With Ruby

This tutorial will cover how to read (or parse) an excel file with ruby. I had to write a script to unpivot some data for a co-worker that saved him hours of time, and I got to write a ruby script, so it was a win-win. Here’s how you can do the same thing. Bookmark [...]

Tuesday, September 18th, 2007

Easy XML Generation with Ruby and ERB

Ah, the bracket tax. XML-Situps, whatever you want to call them, if you write any code (especially if you use java) it should be your sworn enemy. The other day I had to create about 40 XML files for some Java Webstart configs. Instead of doing them by hand, I decided to check out the [...]

Friday, September 14th, 2007

Capturing STDERR with ruby backticks

I was writing a ruby script today that ran a linux command for every line in a file. The problem was the backtick operator in ruby only captures stdout, here's a little trick to get stderr as well. (*nix only) out = `ourlinuxcmd 2>&1` the 2>&1 bit tells the shell to redirect stderr to stdout [...]

Monday, September 10th, 2007

Running rails with mongrel for a specific sub directory

I've started using mongrel for running rails apps with apache2 and mod_proxy , it works like a charm and allows you to run multiple rails apps and mongrel instances on one server. Your proxy setup looks like this in your httpd.conf or vhost.conf <VirtualHost *:80>     ServerName myapp.com     ServerAlias www.myapp.com     [...]

Tuesday, April 3rd, 2007

Scraping IMDB with Ruby and Hpricot

One service that cries for a nice web service interface is IMDB, however they like want $$ or something for it...the nerve! With just a few lines of ruby we can query to our heart's content. In this post I'll go over how to create a very simple class for extracting information about movies from [...]

Wednesday, December 20th, 2006

Importing an MS Project Plan into Basecamp using Ruby

Basecamp is a web based project management tool. It's just fun to use. Microsoft Project....not so much. That being said MS Project does a whole lot of stuff that Basecamp doesn't. Being leet web 2.0 doods we want to use Basecamp! Of course MS Project is the standard that most clients like to see, so [...]

Monday, October 16th, 2006

Derived Columns in ActiveRecord

Sometimes it's useful to have a field in your ActiveRecord implentation that isn't actually selected in your query or present in your table. One way to acheive this is by simply adding a new accessor to your Model class. Let's say we have a table named Customers that has a firstname and lastname column but [...]

Friday, October 6th, 2006

Randomizing an array in Ruby

Ruby's Array class has no method to randomize the contents of an array. Of course, Array can easily be extended to include this functionality. And like anything else in Ruby, there's more than one way to do it. Here's one way: class Array   def randomize     arr=self.dup     self.collect { arr.slice!(rand(arr.length)) } [...]