Malfeasance in 64-bit PowerPC MySQL Gem Compilation

Posted on May 12, 2008

For the three people in the world building the Rails mysql gem on a PowerPC G5-based OS X Server with the 64-bit MySQL installed getting this crazy error:

lazy symbol binding failed: Symbol not found: _mysql_init

The magic ninja gem install command that will cure all your ills goes a little something like this:

sudo env ARCHFLAGS="-arch ppc64" gem install -V mysql -- --with-mysql-include=/usr/local/mysql/include/ --with-mysql-lib=/usr/local/mysql/lib --with-mysql-config=/usr/local/mysql/bin/mysql_config --with-mysql-dir=/usr/local/mysql

Pretty obvious when you think about it. Not sure why it took me a little over an hour to discover the crucial lynchpin for correcting this system-wide thought-tastrophy.

CSS Templating with Sass

Posted on July 09, 2007

I don’t hear many people talking about Sass, but it is indeed fantastic. Basically, Sass is kind of like the Smarty of CSS Templating. Sass files compile to CSS after every change just like Smarty’s TPL files compile directly to PHP. Sass fits well into the Rails don’t-repeat-yourself methodology because you can define color and style constants within CSS rather than explicitly specifying them twenty times. The beauty of Sass is that you get a level of abstraction without any runtime overhead. As a result, Sass performs well and allows quick updates to color schemes and typography without resorting to perl/find or ninja text editor foo. So, why aren’t more people using it?

Ruby CAPTCHA / Ruby-GD StringFT Errors Revisited

Posted on July 09, 2007

Well, I finally solved the “undefined method `stringFT' for GD::Image:Class” error under Mac OS X. The rb-gd darwinport seems to have fallen off the face of the earth. Fortunately, I’ve learned that you can download the source from ruby-lang.org. So, I just rolled my own GD.bundle.

wget http://raa.ruby-lang.org/cache/ruby-gd/ruby-GD-0.7.4-1.tar.gz
cd ruby-GD-0.7.4
ruby extconf.rb --with-freetype --with-xpm --with-ttf
make
sudo make install
sudo mv /usr/local/lib/ruby/site_ruby/1.8/i686-darwin8.8.2/GD.bundle /usr/local/lib/ruby/1.8/i686-darwin8.8.2/

This only works if you have an up-to-date ruby installed under /usr/local (via the Hivelogic instructions). If you’ve installed from ports or are using the older ruby shipped with Leopard, you’ll need to switch your prefix to /opt/local or /usr respectively.

Problems with Ruby’s CAPTCHA gem

Posted on June 11, 2007

Even though gd, gd-devel and the ruby GD and CAPTCHA gems were installed on my Red Hat Enterprise Linux 4 server, Ruby’s CAPTCHA gem seemed to blow-up with the error:

undefined method `StringFT'

Hmmm. I googled around and found that you need a library to bind the GD calls to ruby. This makes perfect sense, but documentation for the issue is scarce.

Eventually, I found the following rpm and installed it.

wget http://ftp.at.gnucash.org/opsys/linux/redhat.com/contrib/libc5/i686/ruby-GD-1.0_97111
rpm -ivh ruby-GD-0.7.4-0vl1.i386.rpm

Unfortunately, the RPM assumed that ruby would be installed under /local, but on RHEL everything is under /usr. So, I found where the RPM stored the library and relocated it to the proper directory.

$ rpm -qpl ruby-GD-0.7.4-0vl1.i386.rpm
/local/lib/site_ruby/1.8/i386-linux/GD.so
sudo mv /local/lib/site_ruby/1.8/i386-linux/GD.so /usr/lib/site_ruby/1.8/i386-linux/

Lo and behold, Ruby’s CAPTCHA gem worked like the clappers after this was sorted. Unfortunately, it took me over an hour to sort out the problem. It would seem that something as mundane as CAPTCHA would have just worked under Rails. The major problem seems to be that the ruby-gd maintainer’s site http://tam.0xfa.com is out of commission.

Under Mac OS X, it’s a bit easier because you can use Darwin Ports to install rb-gd. However, that install appeared to bomb for me because I’m using the latest ruby compiled via the Hivelogic instructions. I attempted to symbolically link the ruby binaries to /opt/local/bin, but that didn’t resolve the issue. I’m still looking for a workaround to this.

Iterating Through The Last 30 Days with Ruby on Rails

Posted on June 10, 2007

Recently, I attempted to create a loop in Ruby on Rails that iterated through the last month worth of dates. Stupidly, I just typed in the following code, and tried to run it… (you need to require ActiveSupport for month.ago to work.

# This code does not work
1.month.ago.step(Time.now, 1.day) { |d|
  print d.day,"\\n"
}

Unfortunately, that doesn’t work, because ActiveSupport returns a Time class value for month.ago. Ruby’s Time class doesn’t define a step method. So, being lazy, I just casted the time to an integer with to_i, and constructed the following loop which does work.

1.month.ago.to_i.step(Time.now.to_i,1.day.to_i) { |d|
   print Time.at(d).day,"\\n"
}

Later on, I learned that Date’s have a step class. So, I simplified the loop.

1.month.ago.to_date.step(Time.now.to_date, 1.day) { |d|
    print d.day,"\\n"
}

It seems like there should be an easier way to do this though. Does anyone have a better idea?

Planet Genius

Posted on December 30, 2006

Well, The Chupacabra has finally started a new blog. This prompted me to assemble my ragtag assortment of feeds and jigger them into a planet site for easy consumption on rainy days when I run out of milk (e.g. Tuesdays). As a homage to Chupa paying his $30 to Bob, I have named the site Planet Genius. This site combines all of the A-list bloggers that I know personally (Chupa, Nugget, Bumper, Ivo, Decibel, Doppler, and Moonwick) onto one page on the thirty of each hour just like the clappers. Stay tuned for when I RJS those star ratings and add an RSS feed to the page.

Ruby $1 vs \1

Posted on May 25, 2006

I was attempting to take some unordered SQL values and order them today with a single line of ruby. Essentially, the sql values look like (1, "value1"), (2, "value2"), and so on. I started out with this, but I couldn’t for the life of me figure out why the gsub statement wouldn’t work.

INCORRECT: ruby -e " y = []; STDIN.readlines.each { |x| if x=~/^\(/; y[x.gsub(/\(([0-9]+),.*/, $1.to_s).to_i]=x; end }; y.each { |z| puts z if ! z.nil?; } " < unordered.sql > ordered.sql

The weird thing is, if I take the if x=~ /^\(/; statement out, the code works. So, someone in #ruby-lang on Freenode reminded me that I need to use '\1' instead of $1.to_s in this case. I ran into this once before, however, I’m still not 100% sure on what the exact rules are for the syntax. So, this was the correct way to do it.

CORRECT: ruby -e " y = []; STDIN.readlines.each { |x| if x=~/^\(/; y[x.gsub(/\(([0-9]+),.*/, '\1').to_i]=x; end }; y.each { |z| puts z if ! z.nil?; } " < unordered.sql > ordered.sql

File_column Problems

Posted on April 20, 2006

OK, how do I make file_column work? I did the following (after installing file_column) which seems like it could be correct, however, it doesn’t work.

1.) Added a database migration


class AddOpmlFileColumn < ActiveRecord::Migration
  def self.up
    create_table :opmlfiles do |table|
      table.column :id, :integer, :null=>false
      table.column :file_name, :string, :null=>false
      table.column :created_at, :datetime
      table.column :user_id, :integer, :null=>false, :default=>'0'
    end
  end

def self.down
  drop_table :opmlfiles
end

end

2.) Created an Opmlfile model

class Opmlfile < ActiveRecord::Base
  file_column :opmlfile
end

3.) Updated the generated controller’s constructor

class OpmlfilesController < ApplicationController
  def new
    if request.get?
      @opmlfile = Opmlfile.new
    else
    	@opmlfile = Opmlfile.new(params[:opmlfile])
    	@opmlfile.save
    end
  end

4.) Designed an upload form

<%= start_form_tag :action => 'create', :multipart => true %>
<p>Upload file:
<%= file_field('opmlfile', 'file_name') %>
<%= submit_tag('Upload file') %>
<%= end_form_tag %>
<%= link_to 'Back', :action => 'list' %>
</p>

OK, the thing is, it looks like it is uploading during the HTTP POST, however, I don’t get any files in my public directory. An opmlfiles directory was created, but nothing ever gets there. Also, the filename is always blank in the model and database. What the heck am I doing wrong?

Update: SOLVED!!!!

BLARGH! The last problem was that my form needed to be defined as this:

<%= start_form_tag({ :action => 'create' }, :multipart => true) %>

and NOT this:

<%= start_form_tag(:action => 'create', :multipart => true) %>

Rails was erroring with “Do not know how to handle a string with value ‘hoyhoy.opml’ that was passed to a file_column” before I made the change.

Also, dopplertx was indeed correct, I needed to have a column in my database table for the filename. It is called file_column after all. Thanks everyone.