Tag Archives: Ruby

Ruby Shoes Build Error On Ubuntu

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

1
2
3
4
5
6
7
8
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:

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

Import CSV Using Rails Migration

Reposted from Rails Weenie:

Install FasterCSV ('gem install fasterCSV')

The code to use inside the migration is similar to:

1
2
3
4
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

Comparing Directories Ruby Style

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require 'ftools'
srcDir = "/home/Music/"
destDir = "/home/Music/iTunes/iTunes Music"
 
mHash = Hash.new
iHash = 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] = path
    end
 
puts "Source # Files: " + mHash.length.to_sputs "Dest # Files: " + iHash.length.to_s
 
#Compare Hashes and copy Any data
 Hash.each_key do |key|
    if iHash[key] == nil  
        puts "Copying " + mHash[key] +" to " + destDir
        File.copy(mHash[key],destDir+"/")   
    end
end

Superators

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