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?

The Plural of Feedback is Feedbacks

Posted on March 21, 2007

According to Ruby on Rails it is. WTF!?

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'active_record'
=> true
irb(main):003:0> Inflector.pluralize('feedback')
=> "feedbacks"
irb(main):004:0>

Discuss.

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.

Generating MP3 Durations with PHP and DBDO

Posted on November 16, 2006

I had to update a MySQL database full of mp3 names with the inherent track, album, and genre metadata. So, I grabbed the Zend mp3 library and sorted it out like the clappers using the DataObjects ORM.

    $m = new DataObjects_Tracks;
    $m->addWhere("filename RLIKE '[.period.]mp3′");
    $m->find();
    while($m->fetch()) {
        $mp3 = new MP3($m->filename);
        $mp3->get_id3();
        $mp3->get_info();
        $m->duration = $mp3->info["length"];
        $m->album = $mp3->info["album"];
        $m->title = $mp3->info["title"];
        $m->update();
    }

If ORMs were automobiles, DB_DataObject would be somewhere between a 1976 Pinto and an Edsel, but it gets the job done OK. The most annoying thing about it is that you have to run php DB/DataObject/createTables.php every time you alter the database. Unfortunately, the more I use DBDO the more I miss the ActiveRecord sauce. Once you’ve driven a Porsche, you don’t want to go back to the old Rustang.

Hencode

Posted on June 19, 2006

I’ve been meaning to do this for a while, but never got around to it until tonight. Enter some text into this text box, click “Translate” to see what it looks like in Hencode, a nonsensical alphabet of my design. Note: only letters, period, and space are defined right now. Numbers and special charcters don’t exist yet.

RedCloth Hoyhoy Bug?

Posted on June 13, 2006

I observed this behavior in Instiki which isn’t what I expect. I don’t know if it is a bug or not, but it kind of looks like one from where I’m sitting. I’m can work around it by specifying links directly (id=”#link”).

irb(main):002:0> require 'redcloth'
=> true
irb(main):007:0> RedCloth.new("p(link). blah").to_html
=> "<p class="link">blah</p>"
irb(main):008:0< RedCloth.new("-- p(link). blah").to_html
=> "<p>&#8212;p(link). blah</p>"

I would expect the red output to be:
=> "&#8212; <p class="link">blah</p>"

Update: Ok, apparently, a “p” tag is only valid at the start of a paragraph (at the beginning of the file or after a newline). So, I’m totally wrong which is par for the course. Thanks to the infamous John Whitley for setting me straight. I shall never again doubt ruby code from _why.