Again, the MySQL ruby gem totally annyoed me trying to install it on a fresh Mac OS X 10.5.5 install and MySQL 5.0.67.
This time the following command brought it to life:
sudo env ARCHFLAGS="-arch i386" gem install mysql -- \
--with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
--with-mysql-include=/usr/local/mysql/include
Thanks to a bitter software engineer.
Share This
Times in RSS Feeds and the like are formatted as RFC3339 most of the time. You can save yourself from strftime by using
Share This
A regular expression to replace all ampersands (&) in a text that are not part of an entity:
t = t.gsub(/&(?!#?\w+;)/, '&')
Language is ruby. The regexp feature used is called a negative lookahead.
Share This
I use rmagick when it comes to deal with images. I’m not that disappointed like Zed Shaw with rmagick (but Zed is totally right when he points out on page 4: “[…] and is difficult to install (unless your computer is nearly exactly the same as the author’s).”), but when it comes to deal with EXIF, rmagick sucks big time.
After some searching i found another EXIF reader called “EXIF Reader” (EXIFR), which can be downloaded and installed from here or via gems.
I came mainly to this point becaus rmagick completly failed reading GPS data from my images (and it is hard to use with all other values).
EXIFR on the contrast cannot do image manipulation, so i needed both. Maybe i’m still just to new to ruby, but exifr gave me a hard time not reading the same image twice from file, once for rmagick and once for exifr.
I came up with the following solution:
require 'rubygems'
require 'RMagick'
require 'exifr'
image = Magick::ImageList.new("whatever_image.jpg")
exif_info = case image.format
when 'JPEG'
EXIFR::JPEG.new(StringIO.new(image.to_blob))
when 'TIFF'
EXIFR::TIFF.new(StringIO.new(image.to_blob))
else
nil
end
This uses rmagick to instantiate a magick image and then a StringIO object to build up the exif information if the image is a jpeg or a tiff image.
Share This
I just discovered the great x_send_file plugin and technique and use it extensivly for daily fratze. I replaced the majority of send_file calls with x_send_file but not all (the in memory thingies i serve cannot be send through apache). This works great in production mode but in development mode, it fails as there is no apache sitting in front the mongrels. Therefore i added the following to my $app_home/config/environments/development.rb:
class ActionController::Base
def x_send_file(path, options = {})
send_file(path, options)
end
end
So all calls to x_send_file in dev mode are delegated to the original send_file.
If anyone can present me a cleaner solution, i.e. with method aliasing, feel free to drop a comment.
Share This