RB_USER_INSTALL to the rescue
If you try to install gems with extensions as non-root user, you will fail (in general)!
For example, installing hpricot results in the following error message on my FreeBSD 7.2 machine:
make install /usr/bin/install -c -o root -g wheel -m 0755 hpricot_scan.so /home/username/GEMS/gems/hpricot-0.8.1/lib install: /home/username/GEMS/gems/hpricot-0.8.1/lib/hpricot_scan.so: chown/chgrp: Operation not permitted *** Error code 71
The file rbconfig.rb contains some info how you're ruby version has been built.
$ pkg_info -L ruby-1.8.\* | grep rbconfig.rb /usr/local/lib/ruby/1.8/i386-freebsd7/rbconfig.rb
It containes the following interessting line:
CONFIG["INSTALL"] = ENV['RB_USER_INSTALL'] ? '/usr/bin/install -c' : '/usr/bin/install -c -o root -g wheel'
So, by default, gem extensions will be installed as user root of group wheel on my system. On the other hand, if RB_USER_INSTALL gets set as environment variable, gems will install with the permissions of the user calling gem install!
Installation von FuzzyFinder: TextMate
FuzzyFinder: TextMate ist eine Erweiterung von jamis fuer das Fuzzyfinder VIM script. Damit laesst sich die Tastenkombination Cmd+T von TextMate unter Vim nachempfinden.
Vim muss mit Ruby-Unterstuetzung kompiliert sein. Das testet man in vim mit :version. Ruby-Unterstuetzung ist angeschaltet, falls man eine Zeile mit dem Text +ruby findet.
Dies sollte bei den meisten Linux-Distributionen der Fall sein. Unter Mac OS X bietet sich MacVim an.
Ruby-Erweiterung installieren:
$ mkdir -p ~/.vim/ruby $ curl "http://github.com/jamis/fuzzy_file_finder/tree/master%2Flib%2Ffuzzy_file_finder.rb?raw=true" > ~/.vim/ruby/fuzzy_file_finder.rb
Vim-Plugins installieren:
$ mkdir -p ~/.vim/plugin # zuerst FuzzyFinder selbst $ curl "http://www.vim.org/scripts/download_script.php?src_id=9306" > ~/.vim/plugin/fuzzyfinder.vim # anschliessend FuzzyFinder: TextMate $ curl "http://github.com/jamis/fuzzyfinder_textmate/tree/master%2Ffuzzyfinder_textmate.vim?raw=true" > ~/.vim/plugin/fuzzyfinder_textmate.vim
Shortcut einrichten (nur ein Vorschlag!):
echo "map <leader>t :FuzzyFinderTextMate<CR>" >> ~/.vimrc
Weiter geht es mit der Benutzung von FuzzyFinder:TextMate.
Ruby Code Snippet: Subsets
I needed a class/function/... to get all subsets and their complements for a given set. Welcome the (quick and dirty) class Subsets! (Idea)
irb(main):001:0> require 'subsets'
=> true
irb(main):002:0> Subsets.generate([1,2])
=> [[[], [1, 2]], [[1], [2]], [[2], [1]], [[1, 2], []]]
irb(main):003:0> Subsets.generate([1,2]).each do |s,c|
irb(main):004:1* puts "subset #{s.inspect} complement #{c.inspect}"
irb(main):005:1> end
subset [] complement [1, 2]
subset [1] complement [2]
subset [2] complement [1]
subset [1, 2] complement []
=> [[[], [1, 2]], [[1], [2]], [[2], [1]], [[1, 2], []]]
irb(main):006:0>
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 class Subsets private_class_method :new # Generates all subsets and their complements def Subsets.generate(set) # :yields: subset, complement n = set.size mask = Array.new(n, false) if block_given? yield([], set) else ret = [[[], set]] end while( Subsets.next_mask(mask,n) ) do subset, complement = Subsets.generate_subset(mask,n,set) if block_given? yield( subset, complement ) else ret << [subset, complement] end end return ret if not block_given? end private def Subsets.next_mask(mask,n) i = 0 while (i < n and mask[i]) mask[i] = false i += 1 end if i < n mask[i] = true; return true end return false end def Subsets.generate_subset(mask,n,set) subset = [] complement = [] for i in 0..n-1 if mask[i] subset << set[i] else complement << set[i] end end return subset, complement end end
Ruby Fun [FreeBSD Ports]
#!/usr/bin/env ruby # lists installed ports and their size usage in descending order $total = 0 ports = Array.new Port = Struct.new("Port", :name, :size) # scan for port name and size `pkg_info -s -a`.scan(/Information\sfor\s(.*?):\n\nPackage\sSize:\n(.*?)\t\(/) do |entry| port = Port.new port.name, port.size = $1, $2.to_i ports << port $total += $2.to_i # add size to total size end # print ordered port list ports.sort{ |x,y| y.size <=> x.size }.each do |port| puts port.name.ljust(40) + "| " + port.size.to_s.rjust(7) end puts "Total size is #{$total}."
% ruby ports_size_usage.rb en-openoffice.org-US-2.0.1 | 276987 linux_base-8-8.0_10 | 240106 teTeX-texmf-3.0_3 | 200259 acroread7-7.0.1 | 95343 erlang-r10b9,1 | 93900 scorched3d-0.39.1_1 | 88966 mono-1.1.9.2_3 | 65423 koffice-1.4.2_2,1 | 62141 kdebase-3.5.0 | 58359 kdepim-3.5.0 | 56011 kdelibs-3.5.0 | 54459 ruby18-rmagick-1.9.3_1 | 52515 qt-copy-3.3.5 | 45350 firefox-1.5_5,1 | 43069