Archive

Archive for the ‘Ruby’ Category

Ruby Shoes Build Error On Ubuntu

March 19, 2008 Leave a comment

When I tried to compile Ruby Shoes I got the following error:

CC shoes/app.c
In file included from /usr/include/signal.h:333,
from /usr/include/sys/ucontext.h:23,
from /usr/include/ucontext.h:27,
from /usr/lib/ruby/1.8/i486-linux/node.h:378,
from shoes/app.c:11:
/usr/include/bits/sigcontext.h:28:29: error: asm/sigcontext.h: No such file or directory
make: *** [shoes/app.o] Error 1

The fix is this:

cd /usr/include/
sudo ln -s asm-i386/ asm

Categories: Ruby, Shoes, Ubuntu

Import CSV Using Rails Migration

October 10, 2007 5 comments

Reposted from Rails Weenie:

Install FasterCSV (‘gem install fasterCSV’)

The code to use inside the migration is similar to:

FasterCSV.foreach(“#{RAILS_ROOT}/lib/symbols_database/security_list.csv“, :row_sep => “\r”) do |row|
field1,field2,field3 = row
Foo.create(:field1 => field1, :field2 => field2, :field3 => field3)
end

Categories: Ruby, RubyGems, Uncategorized

Comparing Directories Ruby Style

October 8, 2007 Leave a comment

I recently needed to recursively compare 2 directories by filename. Here’s the solution:

require 'ftools' 
srcDir = "/home/Music/"destDir = "/home/Music/iTunes/iTunes Music"

mHash = Hash.newiHash = Hash.new
 #Add all files to hash Dir[srcDir + '/**/*.mp3'].each do |path|    mHash[path.split('/').last] = pathend

#Add all files to second hash Dir[destDir + "/**/*.mp3"].each do |path|    iHash[path.split('/').last] = pathend

puts "Source # Files: " + mHash.length.to_sputs "Dest # Files: " + iHash.length.to_s

#Compare Hashes and copy Any datam Hash.each_key do |key|     if iHash[key] == nil         puts "Copying " + mHash[key] +" to " + destDir         File.copy(mHash[key],destDir+"/")         end end
Categories: Ruby

Superators

September 13, 2007 Leave a comment

This is just to cool. Superators are a way to overload the traditional, non logical ruby operators. Check it out.

Categories: Ruby