Archive for the 'Ruby' Category

The state of Linux package managemen sucks.

So here I am, wanting to set up a demo of something I’m working on for the public internets. I figure that since I have this big Cisco IPTV machine which will eventually replace Eron sitting here, I should go ahead and set my demo up on that.

And that is where my woes begin. Desu is running Debian and the project I’m working on is with Rails. Debian uses Apt for package management; Ruby uses Gems. Desu has *only* had Subversion, Apache2, and some webDAV module for Apache installed on it. No MySQL, no Ruby, no Gems, and certainly no ImageMagick.

I spend a few minutes installing Ruby. That’s a big ol’ apt-get install ruby irb rdoc ri because, you know, making a ruby-developers metapackage with the whole kit and kaboodle would be too much to ask from the Ubuntu folks. Instead, they just confuse the living shit out of mister Wow-web-2.0-is-cool-let-me-try-this-Ruby-stuff-out! because he’ll only type apt-get install ruby and then have no idea why IRB is not starting.

Then I go ahead and grab the latest version of Gems from RubyForge. I have no idea if there’s a package for this in the Ubuntu repositories, but I won’t bother with it, especially since Desu has Dapper on it. Since Gems can update itself, that’s not too big of a deal — or is it? Why should I need to install anything from a tarball?

But then, I go on to install my gems.

nevans@desu:~$ sudo gem install -y mysql rmagick rails mongrel

This fails spectacularly. I was missing a Ruby -dev package that I needed. I reran the command; it bombed out again. I tried installing a few MySQL packages until it worked. Then I installed the ImageMagick libraries (and the -dev!) to head off the next failure.

And then it struck me; why the hell do I need to worry about dependencies? I thought package managers were supposed to worry about those for me since it’s like, a computer and I’m a human being whose time is valuable.

Because Apt and Gems are two different package managers, of course! So, guys, where’s my meta-get install gems:rmagick gems:mysql gems:rails gems:mongrel?

Automagic Validation

I have a new test in my Rails arsenal: assert_valid_markup.

def assert_valid_markup(markup=@response.body)
  require 'net/http'
  response = Net::HTTP.start('validator.w3.org') do |w3c|
  query = 'fragment=' + CGI.escape(markup) + '&output=xml'
    w3c.post2('/check', query)
  end
  assert_equal 'Valid', response['x-w3c-validator-status']
end

Validating (X)HTML In Rails.

RailsDay & More

First and foremost - oops, looks like I didn’t get my four posts last week. Oh well. Maybe three a week is more reasonable…or I’m way too fucking lazy. Sheesh.

But on to business. I had planned to add another entry yesterday, but I got sidetracked. On Friday, Al asked me if I would be interested in joining him and Josh for their RailsDay2006 project. Since I hadn’t registered, I ended up not actually writing code, but I did do some extreme programming with Josh, without me actually typing anything. We came up with a half-finished e-mail autoresponder called on_vacation (source will be available soon!).

It’s a pretty nifty app. When we did our last checkin, it was able to check someone’s pop3 account for new messages, ensure that we had not responded to the message, queue a response to be sent, mark that e-mail as autoresponded to, and finally send autoresponses. There was also a frontend with a signup/login thing. We didn’t quite get around to implementing an away message management screen, though.


Our Commits

The SuperBestFriends’ Progress

In other news, I did some web designing today. I’m not entirely sure where I’m headed with this, but have a look: freePets.

Ruby Quick Reference

While working on a new thumbnailer to replace the Automatic Thumbnail Production Unit MXX-3005.0, I came across a kickass Ruby ‘quick reference’, similar to the InVisible Ruby on Rails Reference that I love oh so much.

Ryan Davis’ Ruby QuickRef.

REXML, The Ruby XML Parser

Recently, I had a rather frustrating experience with REXML, the XML parser that Ruby >=1.8.4 (and probably older versions, too) ship with. My problem was the extravagently shitty documentation its maintainers provide. This ‘documentation’ is a big tutorial which is unclear on many things.

So, in an effort to help the next hapless programmer who is desperately Googling for some REXML help that isn’t retarded, I will provide you with the following.

# Load REXML
require 'rexml/document'

# Parse our XML
document = REXML::Document.new(some_xml_string)

# Iterate through the root of the document.
# NOTE - I AM NOT USING 'EACH' - SEE BELOW
document.elements[1].each_element do |element|
  # We can access the children of our element
  # with The elements[] array. Same goes for
  # attributes - user attributes[].

  puts element.elements['author']
end

The ‘each’ thing is what got me - each_element loops through and gives you something usable, while each goes through and returns REXML objects with the XML still in them. For example, each would give me ‘ . . . ‘. From there, you cannot use the elements or attributes arrays to get to the children.

Next Page »