nuthole.com "even better than a poke in the eye with a sharp stick"
contact:email
subscribe:feed
2007 08
Powered by Blosxom
Get Firefox!
geourl
subgenius
spampoison hosting rails

Installing RMagick on Mac OS X and Ubuntu

posted by jack at 09:22 CET in / compute / rails feed

I haven't done anything with RMagick at all, partly because it relies on ImageMagick which many consider difficult to install on Mac OS X. Lately I've had a reason to use the excellent Gruff charting library, so it was time to buckle down and install this stuff.

As it turns out, it's really not as complicated as some people say. Assuming you've already got macports and rubygems installed, it basically comes down to this:

sudo port install freetype
sudo port install ghostscript
sudo port install imagemagick
#sudo port install graphicsmagick
sudo gem install rmagick

Somewhere I got the idea to also install graphicsmagick after imagemagick, but for some reason port doesn't seem to be able to find the package; It tries a few dozen sites and fails, so I commented it out above, but feel free to try it yourself. But no matter, it seems to not be necessary; I can now create images, render text, write them to disk, etc.

On Ubuntu (6.10), the incantation is different, but even simpler (via EXPRESSICA:

sudo apt-get install imagemagick
sudo apt-get install libmagick9-dev ruby1.8-dev
sudo gem install rmagick

The only caveat is that if you're running without swap space and have less than a couple hundred megs of free RAM (e.g. on a VPS server) you may need to stop some of your processes before attempting that last line, or you'll get this not-so-helpful set of errors after it runs for a while, consumes all available RAM, and subsequently crashes:

Building native extensions.  This could take a while...
ERROR:  While executing gem ... (Gem::Installer::ExtensionBuildError)
    ERROR: Failed to build gem native extension.
Hopefully this will save someone a few hours.
permalink | digg this | slashdot this | add to del.icio.us |
Comments

My first home-made rake task

posted by jack at 12:53 CET in / compute / rails feed

I wanted to be able to examine my development log for rails deprecation warnings, and came up with this handy one-liner:

grep "^DEPRECATION WARNING:" development.log | awk '{print $3, $4, $5, ":", $NF}' | sort | uniq

This gives me output something like this:

@params is deprecated! : script/../config/../app/views/waiting_messages/prepare_reply.rhtml:9)
@request is deprecated! : ./script/../config/../app/controllers/account_controller.rb:10)
You called render('new_member_in_program'), : /opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/li [...]
end_form_tag is deprecated : script/../config/../app/views/members/bulknew.rhtml:10)
find_all is deprecated : (irb):3)
start_form_tag is deprecated : script/../config/../app/views/members/bulknew.rhtml:2)

It's not perfect; I'm missing some useful info from some of the lines (such as the 'You called render...') that I'll have to go back and pick over. But in broad strokes, it gives me a fairly concise list of some things that need to be cleaned up.

However, that one-liner is fairly meaty. Who wants to remember that, or make an alias for it, or need to look it up? Yuck.

How about a rake task? I've never written one before, but everyone's always raving about how simple it is, so I figured I'd go ahead. Hopefully this helps show how simple it is. While I'm at it, I'll go ahead and include the full text of the warning (except for the redundant "DEPRECATION WARNING" at the beginning, since we already know we're looking for that) instead of truncating it like I did in my awk-based one-liner.

Here it is:


namespace :utils do
  desc "List deprecation warnings in development log"
  task :find_deprecated do
    File.open('log/development.log') do |file|
      lines = file.select {|line| line =~ /^DEPRECATION WARNING:/}
      lines.sort.uniq.each {|line| puts line.split('DEPRECATION WARNING: ')[1]}
    end
  end
end

Put that in a file called utils.rake inside your lib/tasks directory, and call it by typing rake utils:find_deprecated, and you'll get something like this (lines chomped for presentation purposes):


@params is deprecated! Call params.[] instead of @params.[]. Args: [:response_text]  See http://www. [...]
@request is deprecated! Call request.accepts instead of @request.accepts. Args: []  See http://www.r [...]
You called render('new_member_in_program'), which is a deprecated API call. Instead you use render : [...]
end_form_tag is deprecated and will be removed from Rails 2.0  See http://www.rubyonrails.org/deprec [...]
find_all is deprecated and will be removed from Rails 2.0 (use find(:all, ...))  See http://www.ruby [...]
start_form_tag is deprecated and will be removed from Rails 2.0 (use form_tag instead)  See http://w [...]

There are certainly improvements that could be made, such as adding the ability to search test.log and production.log as well, but this'll do for now.

permalink | digg this | slashdot this | add to del.icio.us |
Comments

Your Comment

 
Name:
URL/Email: [http://... or mailto:you@wherever] (optional)
Title: (optional)
Comment:
Save my Name and URL/Email for next time

Looking for programming talent that doesn't make you say "WTF!"? Try the hidden network.