├── bin ├── .svn │ ├── format │ ├── prop-base │ │ └── amazon.svn-base │ ├── text-base │ │ ├── pastie.svn-base │ │ ├── google.svn-base │ │ └── amazon.svn-base │ └── entries ├── pastie ├── google └── amazon ├── html ├── .svn │ ├── format │ ├── prop-base │ │ ├── andreas00.css.svn-base │ │ ├── index.html.svn-base │ │ ├── usage.html.svn-base │ │ ├── authorship.html.svn-base │ │ ├── bg.gif.svn-base │ │ ├── front.jpg.svn-base │ │ ├── test.jpg.svn-base │ │ ├── menubg.gif.svn-base │ │ └── menubg2.gif.svn-base │ ├── text-base │ │ ├── bg.gif.svn-base │ │ ├── front.jpg.svn-base │ │ ├── test.jpg.svn-base │ │ ├── menubg.gif.svn-base │ │ ├── menubg2.gif.svn-base │ │ ├── index.html.svn-base │ │ ├── authorship.html.svn-base │ │ ├── andreas00.css.svn-base │ │ └── usage.html.svn-base │ └── entries ├── bg.gif ├── test.jpg ├── .DS_Store ├── front.jpg ├── menubg.gif ├── menubg2.gif ├── index.html ├── authorship.html ├── andreas00.css └── usage.html ├── lib ├── .svn │ ├── format │ ├── entries │ └── text-base │ │ └── utility_belt.rb.svn-base ├── utility_belt │ ├── .svn │ │ ├── format │ │ ├── text-base │ │ │ ├── is_an.rb.svn-base │ │ │ ├── irb_options.rb.svn-base │ │ │ ├── rails_verbosity_control.rb.svn-base │ │ │ ├── hash_math.rb.svn-base │ │ │ ├── not.rb.svn-base │ │ │ ├── with.rb.svn-base │ │ │ ├── pipe.rb.svn-base │ │ │ ├── irb_verbosity_control.rb.svn-base │ │ │ ├── rails_finder_shortcut.rb.svn-base │ │ │ ├── convertable_to_file.rb.svn-base │ │ │ ├── language_greps.rb.svn-base │ │ │ ├── amazon_upload_shortcut.rb.svn-base │ │ │ ├── pastie.rb.svn-base │ │ │ ├── google.rb.svn-base │ │ │ ├── symbol_to_proc.rb.svn-base │ │ │ ├── clipboard.rb.svn-base │ │ │ ├── equipper.rb.svn-base │ │ │ ├── wirble.rb.svn-base │ │ │ ├── interactive_editor.rb.svn-base │ │ │ ├── string_to_proc.rb.svn-base │ │ │ └── command_history.rb.svn-base │ │ └── entries │ ├── is_an.rb │ ├── irb_options.rb │ ├── rails_verbosity_control.rb │ ├── hash_math.rb │ ├── not.rb │ ├── array_numberings.rb │ ├── with.rb │ ├── pipe.rb │ ├── irb_verbosity_control.rb │ ├── rails_finder_shortcut.rb │ ├── convertable_to_file.rb │ ├── language_greps.rb │ ├── amazon_upload_shortcut.rb │ ├── google.rb │ ├── pastie.rb │ ├── symbol_to_proc.rb │ ├── clipboard.rb │ ├── equipper.rb │ ├── wirble.rb │ ├── interactive_editor.rb │ ├── string_to_proc.rb │ └── command_history.rb └── utility_belt.rb ├── spec ├── .svn │ ├── format │ ├── prop-base │ │ └── interactive_editor_spec.rb.svn-base │ ├── text-base │ │ ├── language_greps_spec.rb.svn-base │ │ ├── utility_belt_spec.rb.svn-base │ │ ├── spec_helper.rb.svn-base │ │ ├── hash_math_spec.rb.svn-base │ │ ├── pipe_spec.rb.svn-base │ │ ├── convertable_to_file_spec.rb.svn-base │ │ ├── string_to_proc_spec.rb.svn-base │ │ ├── equipper_spec.rb.svn-base │ │ ├── pastie_spec.rb.svn-base │ │ └── interactive_editor_spec.rb.svn-base │ └── entries ├── language_greps_spec.rb ├── utility_belt_spec.rb ├── spec_helper.rb ├── hash_math_spec.rb ├── array_numberings_spec.rb ├── pipe_spec.rb ├── convertable_to_file_spec.rb ├── string_to_proc_spec.rb ├── equipper_spec.rb ├── pastie_spec.rb └── interactive_editor_spec.rb ├── History.txt ├── Manifest.txt ├── utility-belt.gemspec └── README /bin/.svn/format: -------------------------------------------------------------------------------- 1 | 8 2 | -------------------------------------------------------------------------------- /html/.svn/format: -------------------------------------------------------------------------------- 1 | 8 2 | -------------------------------------------------------------------------------- /lib/.svn/format: -------------------------------------------------------------------------------- 1 | 8 2 | -------------------------------------------------------------------------------- /spec/.svn/format: -------------------------------------------------------------------------------- 1 | 8 2 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/format: -------------------------------------------------------------------------------- 1 | 8 2 | -------------------------------------------------------------------------------- /html/bg.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gilesbowkett/utility-belt/HEAD/html/bg.gif -------------------------------------------------------------------------------- /bin/.svn/prop-base/amazon.svn-base: -------------------------------------------------------------------------------- 1 | K 14 2 | svn:executable 3 | V 1 4 | * 5 | END 6 | -------------------------------------------------------------------------------- /html/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gilesbowkett/utility-belt/HEAD/html/test.jpg -------------------------------------------------------------------------------- /History.txt: -------------------------------------------------------------------------------- 1 | == 1.0.0 / 2007-11-03 2 | 3 | * 1 major enhancement 4 | * Birthday! 5 | 6 | -------------------------------------------------------------------------------- /html/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gilesbowkett/utility-belt/HEAD/html/.DS_Store -------------------------------------------------------------------------------- /html/.svn/prop-base/andreas00.css.svn-base: -------------------------------------------------------------------------------- 1 | K 14 2 | svn:executable 3 | V 1 4 | * 5 | END 6 | -------------------------------------------------------------------------------- /html/.svn/prop-base/index.html.svn-base: -------------------------------------------------------------------------------- 1 | K 14 2 | svn:executable 3 | V 1 4 | * 5 | END 6 | -------------------------------------------------------------------------------- /html/.svn/prop-base/usage.html.svn-base: -------------------------------------------------------------------------------- 1 | K 14 2 | svn:executable 3 | V 1 4 | * 5 | END 6 | -------------------------------------------------------------------------------- /html/front.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gilesbowkett/utility-belt/HEAD/html/front.jpg -------------------------------------------------------------------------------- /html/menubg.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gilesbowkett/utility-belt/HEAD/html/menubg.gif -------------------------------------------------------------------------------- /html/menubg2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gilesbowkett/utility-belt/HEAD/html/menubg2.gif -------------------------------------------------------------------------------- /html/.svn/prop-base/authorship.html.svn-base: -------------------------------------------------------------------------------- 1 | K 14 2 | svn:executable 3 | V 1 4 | * 5 | END 6 | -------------------------------------------------------------------------------- /lib/utility_belt/is_an.rb: -------------------------------------------------------------------------------- 1 | # is_a? Array bothers me 2 | class Object 3 | alias :is_an? :is_a? 4 | end 5 | -------------------------------------------------------------------------------- /spec/.svn/prop-base/interactive_editor_spec.rb.svn-base: -------------------------------------------------------------------------------- 1 | K 14 2 | svn:executable 3 | V 1 4 | * 5 | END 6 | -------------------------------------------------------------------------------- /html/.svn/text-base/bg.gif.svn-base: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gilesbowkett/utility-belt/HEAD/html/.svn/text-base/bg.gif.svn-base -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/is_an.rb.svn-base: -------------------------------------------------------------------------------- 1 | # is_a? Array bothers me 2 | class Object 3 | alias :is_an? :is_a? 4 | end 5 | -------------------------------------------------------------------------------- /lib/utility_belt/irb_options.rb: -------------------------------------------------------------------------------- 1 | # auto indent, _ special var 2 | IRB.conf[:AUTO_INDENT] = true 3 | IRB.conf[:EVAL_HISTORY] = 1000 4 | -------------------------------------------------------------------------------- /html/.svn/text-base/front.jpg.svn-base: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gilesbowkett/utility-belt/HEAD/html/.svn/text-base/front.jpg.svn-base -------------------------------------------------------------------------------- /html/.svn/text-base/test.jpg.svn-base: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gilesbowkett/utility-belt/HEAD/html/.svn/text-base/test.jpg.svn-base -------------------------------------------------------------------------------- /Manifest.txt: -------------------------------------------------------------------------------- 1 | History.txt 2 | Manifest.txt 3 | README.txt 4 | Rakefile 5 | bin/utility_belt 6 | lib/utility_belt.rb 7 | test/test_utility_belt.rb -------------------------------------------------------------------------------- /html/.svn/text-base/menubg.gif.svn-base: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gilesbowkett/utility-belt/HEAD/html/.svn/text-base/menubg.gif.svn-base -------------------------------------------------------------------------------- /html/.svn/text-base/menubg2.gif.svn-base: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gilesbowkett/utility-belt/HEAD/html/.svn/text-base/menubg2.gif.svn-base -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/irb_options.rb.svn-base: -------------------------------------------------------------------------------- 1 | # auto indent, _ special var 2 | IRB.conf[:AUTO_INDENT] = true 3 | IRB.conf[:EVAL_HISTORY] = 1000 4 | -------------------------------------------------------------------------------- /html/.svn/prop-base/bg.gif.svn-base: -------------------------------------------------------------------------------- 1 | K 14 2 | svn:executable 3 | V 1 4 | * 5 | K 13 6 | svn:mime-type 7 | V 24 8 | application/octet-stream 9 | END 10 | -------------------------------------------------------------------------------- /html/.svn/prop-base/front.jpg.svn-base: -------------------------------------------------------------------------------- 1 | K 14 2 | svn:executable 3 | V 1 4 | * 5 | K 13 6 | svn:mime-type 7 | V 24 8 | application/octet-stream 9 | END 10 | -------------------------------------------------------------------------------- /html/.svn/prop-base/test.jpg.svn-base: -------------------------------------------------------------------------------- 1 | K 14 2 | svn:executable 3 | V 1 4 | * 5 | K 13 6 | svn:mime-type 7 | V 24 8 | application/octet-stream 9 | END 10 | -------------------------------------------------------------------------------- /html/.svn/prop-base/menubg.gif.svn-base: -------------------------------------------------------------------------------- 1 | K 14 2 | svn:executable 3 | V 1 4 | * 5 | K 13 6 | svn:mime-type 7 | V 24 8 | application/octet-stream 9 | END 10 | -------------------------------------------------------------------------------- /html/.svn/prop-base/menubg2.gif.svn-base: -------------------------------------------------------------------------------- 1 | K 14 2 | svn:executable 3 | V 1 4 | * 5 | K 13 6 | svn:mime-type 7 | V 24 8 | application/octet-stream 9 | END 10 | -------------------------------------------------------------------------------- /bin/pastie: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | %w{rubygems utility_belt}.each {|library| require library} 3 | 4 | UtilityBelt.equip(:pastie) 5 | include UtilityBelt::Pastie 6 | 7 | pastie(ARGV[0]) 8 | -------------------------------------------------------------------------------- /bin/google: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | %w{rubygems platform net/http utility_belt}.each {|library| require library} 3 | 4 | UtilityBelt.equip(:google) 5 | include UtilityBelt::Google 6 | 7 | google(ARGV[0]) 8 | -------------------------------------------------------------------------------- /bin/.svn/text-base/pastie.svn-base: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | %w{rubygems utility_belt}.each {|library| require library} 3 | UtilityBelt.equip(:pastie) 4 | include UtilityBelt::Pastie 5 | 6 | pastie(ARGV[0]) 7 | -------------------------------------------------------------------------------- /bin/.svn/text-base/google.svn-base: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | %w{rubygems platform net/http utility_belt}.each {|library| require library} 3 | 4 | UtilityBelt.equip(:google) 5 | include UtilityBelt::Google 6 | 7 | google(ARGV[0]) 8 | -------------------------------------------------------------------------------- /spec/language_greps_spec.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "spec_helper") 2 | require "lib/utility_belt/language_greps" 3 | describe "language greps" do 4 | 5 | it "should handle String#blank?" do 6 | "".should be_blank 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /spec/.svn/text-base/language_greps_spec.rb.svn-base: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "spec_helper") 2 | require "lib/utility_belt/language_greps" 3 | describe "language greps" do 4 | 5 | it "should handle String#blank?" do 6 | "".should be_blank 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /lib/utility_belt/rails_verbosity_control.rb: -------------------------------------------------------------------------------- 1 | # Rails verbosity: http://weblog.jamisbuck.org/2007/1/8/watching-activerecord-do-it-s-thing 2 | # Marcel said they toyed with making this the console default on core 3 | class Object 4 | def log 5 | ActiveRecord::Base.clear_active_connections! 6 | ActiveRecord::Base.logger = Logger.new(STDOUT) 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /spec/utility_belt_spec.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "spec_helper") 2 | # yeah, I know. I know! but you try to write specs for code which launches vi. most of this was 3 | # already written by the time I started tasting the BDD Kool-Aid. HOWEVER! any new patches are 4 | # very welcome, but MUST be accompanied by a spec or an absolutely airtight reason why not. 5 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/rails_verbosity_control.rb.svn-base: -------------------------------------------------------------------------------- 1 | # Rails verbosity: http://weblog.jamisbuck.org/2007/1/8/watching-activerecord-do-it-s-thing 2 | # Marcel said they toyed with making this the console default on core 3 | class Object 4 | def log 5 | ActiveRecord::Base.clear_active_connections! 6 | ActiveRecord::Base.logger = Logger.new(STDOUT) 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # Make sure Rubygems' mangling of the path is already done before we do our own 2 | # mangling. 3 | require 'rubygems' 4 | 5 | # Ensure that when we require UtilityBelt libs they are from the files under 6 | # test, NOT from the installed gem. 7 | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..")) 8 | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib")) 9 | -------------------------------------------------------------------------------- /spec/.svn/text-base/utility_belt_spec.rb.svn-base: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "spec_helper") 2 | # yeah, I know. I know! but you try to write specs for code which launches vi. most of this was 3 | # already written by the time I started tasting the BDD Kool-Aid. HOWEVER! any new patches are 4 | # very welcome, but MUST be accompanied by a spec or an absolutely airtight reason why not. 5 | -------------------------------------------------------------------------------- /lib/utility_belt/hash_math.rb: -------------------------------------------------------------------------------- 1 | class Hash 2 | alias :+ :merge 3 | def -(thing_to_be_deleted) 4 | if thing_to_be_deleted.is_a? Hash 5 | thing_to_be_deleted.each do |key, value| 6 | self.delete(key) if self[key] == value 7 | end 8 | elsif self.keys.include? thing_to_be_deleted 9 | self.delete(thing_to_be_deleted) 10 | end 11 | self 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /spec/.svn/text-base/spec_helper.rb.svn-base: -------------------------------------------------------------------------------- 1 | # Make sure Rubygems' mangling of the path is already done before we do our own 2 | # mangling. 3 | require 'rubygems' 4 | 5 | # Ensure that when we require UtilityBelt libs they are from the files under 6 | # test, NOT from the installed gem. 7 | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..")) 8 | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib")) 9 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/hash_math.rb.svn-base: -------------------------------------------------------------------------------- 1 | class Hash 2 | alias :+ :merge 3 | def -(thing_to_be_deleted) 4 | if thing_to_be_deleted.is_a? Hash 5 | thing_to_be_deleted.each do |key, value| 6 | self.delete(key) if self[key] == value 7 | end 8 | elsif self.keys.include? thing_to_be_deleted 9 | self.delete(thing_to_be_deleted) 10 | end 11 | self 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/utility_belt/not.rb: -------------------------------------------------------------------------------- 1 | # http://blog.jayfields.com/2007/08/ruby-adding-not-method-for-readability.html 2 | class Object 3 | define_method :not do 4 | Not.new(self) 5 | end 6 | class Not 7 | private *instance_methods.select { |m| m !~ /(^__|^\W|^binding$)/ } 8 | def initialize(subject) 9 | @subject = subject 10 | end 11 | def method_missing(sym, *args, &blk) 12 | !@subject.send(sym,*args,&blk) 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/utility_belt/array_numberings.rb: -------------------------------------------------------------------------------- 1 | class Array 2 | def second 3 | self[1] 4 | end 5 | 6 | def third 7 | self[2] 8 | end 9 | 10 | def fourth 11 | self[3] 12 | end 13 | 14 | def fifth 15 | self[4] 16 | end 17 | 18 | def sixth 19 | self[5] 20 | end 21 | 22 | def seventh 23 | self[6] 24 | end 25 | 26 | def eighth 27 | self[7] 28 | end 29 | 30 | def ninth 31 | self[8] 32 | end 33 | 34 | def tenth 35 | self[9] 36 | end 37 | end -------------------------------------------------------------------------------- /lib/utility_belt/with.rb: -------------------------------------------------------------------------------- 1 | # Object#with -- by Dan Yoder, dev.zeraweb.com -- this is something from Pascal 2 | # and JavaScript. here's the use case. 3 | 4 | # instead of: 5 | # some_object.do_x 6 | # some_object.do_y 7 | # some_object.do_z 8 | # 9 | # you can instead do: 10 | # with(some_object) 11 | # do_x 12 | # do_y 13 | # do_z 14 | # end 15 | 16 | class Object 17 | def with(object, &block) 18 | object.instance_eval &block 19 | end 20 | end 21 | 22 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/not.rb.svn-base: -------------------------------------------------------------------------------- 1 | # http://blog.jayfields.com/2007/08/ruby-adding-not-method-for-readability.html 2 | class Object 3 | define_method :not do 4 | Not.new(self) 5 | end 6 | class Not 7 | private *instance_methods.select { |m| m !~ /(^__|^\W|^binding$)/ } 8 | def initialize(subject) 9 | @subject = subject 10 | end 11 | def method_missing(sym, *args, &blk) 12 | !@subject.send(sym,*args,&blk) 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/with.rb.svn-base: -------------------------------------------------------------------------------- 1 | # Object#with -- by Dan Yoder, dev.zeraweb.com -- this is something from Pascal 2 | # and JavaScript. here's the use case. 3 | 4 | # instead of: 5 | # some_object.do_x 6 | # some_object.do_y 7 | # some_object.do_z 8 | # 9 | # you can instead do: 10 | # with(some_object) 11 | # do_x 12 | # do_y 13 | # do_z 14 | # end 15 | 16 | class Object 17 | def with(object, &block) 18 | object.instance_eval &block 19 | end 20 | end 21 | 22 | -------------------------------------------------------------------------------- /spec/hash_math_spec.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "spec_helper") 2 | require "lib/utility_belt/hash_math" 3 | describe "Hash math" do 4 | 5 | it "should add hashes" do 6 | ({:a => :b} + {:c => :d}).should == {:a => :b, :c => :d} 7 | end 8 | 9 | it "should subtract hashes" do 10 | ({:a => :b, :c => :d} - {:c => :d}).should == {:a => :b} 11 | end 12 | 13 | it "should subtract key/value pairs by key" do 14 | ({:a => :b, :c => :d} - :c).should == {:a => :b} 15 | end 16 | 17 | end 18 | -------------------------------------------------------------------------------- /spec/.svn/text-base/hash_math_spec.rb.svn-base: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "spec_helper") 2 | require "lib/utility_belt/hash_math" 3 | describe "Hash math" do 4 | 5 | it "should add hashes" do 6 | ({:a => :b} + {:c => :d}).should == {:a => :b, :c => :d} 7 | end 8 | 9 | it "should subtract hashes" do 10 | ({:a => :b, :c => :d} - {:c => :d}).should == {:a => :b} 11 | end 12 | 13 | it "should subtract key/value pairs by key" do 14 | ({:a => :b, :c => :d} - :c).should == {:a => :b} 15 | end 16 | 17 | end 18 | -------------------------------------------------------------------------------- /lib/.svn/entries: -------------------------------------------------------------------------------- 1 | 8 2 | 3 | dir 4 | 68 5 | svn+ssh://giles_bowkizzo@rubyforge.org/var/svn/utilitybelt/lib 6 | svn+ssh://giles_bowkizzo@rubyforge.org/var/svn/utilitybelt 7 | 8 | 9 | 10 | 2008-02-22T16:54:56.894766Z 11 | 68 12 | avdi 13 | 14 | 15 | svn:special svn:externals svn:needs-lock 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 624654a9-0480-469b-a93b-0723543e320f 28 | 29 | utility_belt 30 | dir 31 | 32 | utility_belt.rb 33 | file 34 | 35 | 36 | 37 | 38 | 2008-01-14T07:17:14.000000Z 39 | f0f3e70937f6aac761a9626f2abc82e0 40 | 2008-01-13T21:36:35.002431Z 41 | 58 42 | cypher 43 | 44 | -------------------------------------------------------------------------------- /bin/amazon: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | %w{rubygems platform optparse}.each {|library| require library} 3 | 4 | # command-line args 5 | option_parser = OptionParser.new 6 | option_parser.on("-b", "--bucket NAME", String) {|bucket| @bucket = bucket unless bucket.empty?} 7 | filenames = option_parser.parse(ARGV) 8 | abort "Usage: amazon -b bucket_name file_name" unless @bucket && filenames 9 | 10 | # require files, populate hash 11 | require 'utility_belt' 12 | UtilityBelt.equip(:amazon_upload_shortcut) 13 | include UtilityBelt::AmazonUploadShortcut 14 | 15 | # baddabing, baddaboom 16 | filenames.each {|filename| puts aws_upload(@bucket, filename)} 17 | -------------------------------------------------------------------------------- /bin/.svn/text-base/amazon.svn-base: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | %w{rubygems platform optparse}.each {|library| require library} 3 | 4 | # command-line args 5 | option_parser = OptionParser.new 6 | option_parser.on("-b", "--bucket NAME", String) {|bucket| @bucket = bucket} 7 | filenames = option_parser.parse(ARGV) 8 | abort "Usage: amazon -b bucket_name file_name" unless @bucket && filenames 9 | 10 | # require files, populate hash 11 | require 'utility_belt' 12 | UtilityBelt.equip(:amazon_upload_shortcut) 13 | include UtilityBelt::AmazonUploadShortcut 14 | 15 | # baddabing, baddaboom 16 | filenames.each {|filename| puts aws_upload(@bucket, filename)} 17 | -------------------------------------------------------------------------------- /lib/utility_belt/pipe.rb: -------------------------------------------------------------------------------- 1 | # This extension adds a UNIX-style pipe to strings 2 | # 3 | # Synopsis: 4 | # 5 | # >> puts "UtilityBelt is better than alfalfa" | "cowsay" 6 | # ____________________________________ 7 | # < UtilityBelt is better than alfalfa > 8 | # ------------------------------------ 9 | # \ ^__^ 10 | # \ (oo)\_______ 11 | # (__)\ )\/\ 12 | # ||----w | 13 | # || || 14 | # => nil 15 | # 16 | class String 17 | def |(cmd) 18 | IO.popen(cmd, 'r+') do |pipe| 19 | pipe.write(self) 20 | pipe.close_write 21 | pipe.read 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/pipe.rb.svn-base: -------------------------------------------------------------------------------- 1 | # This extension adds a UNIX-style pipe to strings 2 | # 3 | # Synopsis: 4 | # 5 | # >> puts "UtilityBelt is better than alfalfa" | "cowsay" 6 | # ____________________________________ 7 | # < UtilityBelt is better than alfalfa > 8 | # ------------------------------------ 9 | # \ ^__^ 10 | # \ (oo)\_______ 11 | # (__)\ )\/\ 12 | # ||----w | 13 | # || || 14 | # => nil 15 | # 16 | class String 17 | def |(cmd) 18 | IO.popen(cmd, 'r+') do |pipe| 19 | pipe.write(self) 20 | pipe.close_write 21 | pipe.read 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /lib/utility_belt/irb_verbosity_control.rb: -------------------------------------------------------------------------------- 1 | # IRB verbosity: http://groups.google.com/group/ruby-talk-google/browse_thread/thread/9c1febbe05513dc0 2 | module IRB 3 | def self.result_format 4 | conf[:PROMPT][conf[:PROMPT_MODE]][:RETURN] 5 | end 6 | def self.result_format=(str) 7 | result_format.replace(str) 8 | end 9 | def self.show_results 10 | self.result_format = "=> %s\n" 11 | end 12 | def self.hide_results 13 | self.result_format = '' 14 | end 15 | end 16 | 17 | class Object 18 | def verbose 19 | IRB.show_results 20 | end 21 | alias :v :verbose 22 | 23 | def quiet 24 | IRB.hide_results 25 | end 26 | alias :q :quiet 27 | 28 | alias :x :exit 29 | end 30 | 31 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/irb_verbosity_control.rb.svn-base: -------------------------------------------------------------------------------- 1 | # IRB verbosity: http://groups.google.com/group/ruby-talk-google/browse_thread/thread/9c1febbe05513dc0 2 | module IRB 3 | def self.result_format 4 | conf[:PROMPT][conf[:PROMPT_MODE]][:RETURN] 5 | end 6 | def self.result_format=(str) 7 | result_format.replace(str) 8 | end 9 | def self.show_results 10 | self.result_format = "=> %s\n" 11 | end 12 | def self.hide_results 13 | self.result_format = '' 14 | end 15 | end 16 | 17 | class Object 18 | def verbose 19 | IRB.show_results 20 | end 21 | alias :v :verbose 22 | 23 | def quiet 24 | IRB.hide_results 25 | end 26 | alias :q :quiet 27 | 28 | alias :x :exit 29 | end 30 | 31 | -------------------------------------------------------------------------------- /lib/utility_belt/rails_finder_shortcut.rb: -------------------------------------------------------------------------------- 1 | # http://www.clarkware.com/cgi/blosxom/2007/09/03#ConsoleFindShortcut 2 | # Mike Clark's find() shortcut for Rails console 3 | 4 | # Creates shortcut methods for finding models. 5 | UTILITY_BELT_IRB_STARTUP_PROCS[:define_model_find_shortcuts] = proc do 6 | if defined? ActiveRecord::Base || defined? ActiveResource::Base 7 | model_files = Dir.glob("app/models/**/*.rb") 8 | table_names = model_files.map { |f| File.basename(f).split('.')[0..-2].join } 9 | table_names.each do |table_name| 10 | Object.instance_eval do 11 | define_method(table_name) do |*args| 12 | table_name.camelize.constantize.send(:find, *args) 13 | end 14 | end 15 | end 16 | end 17 | end 18 | # note: Mike wrote this for ARec, but it works on ARes too since it doesn't hit the DB 19 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/rails_finder_shortcut.rb.svn-base: -------------------------------------------------------------------------------- 1 | # http://www.clarkware.com/cgi/blosxom/2007/09/03#ConsoleFindShortcut 2 | # Mike Clark's find() shortcut for Rails console 3 | 4 | # Creates shortcut methods for finding models. 5 | UTILITY_BELT_IRB_STARTUP_PROCS[:define_model_find_shortcuts] = lambda do 6 | if defined? ActiveRecord::Base || defined? ActiveResource::Base 7 | model_files = Dir.glob("app/models/**/*.rb") 8 | table_names = model_files.map { |f| File.basename(f).split('.')[0..-2].join } 9 | table_names.each do |table_name| 10 | Object.instance_eval do 11 | define_method(table_name) do |*args| 12 | table_name.camelize.constantize.send(:find, *args) 13 | end 14 | end 15 | end 16 | end 17 | end 18 | # note: Mike wrote this for ARec, but it works on ARes too since it doesn't hit the DB 19 | -------------------------------------------------------------------------------- /spec/array_numberings_spec.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "spec_helper") 2 | require "lib/utility_belt/array_numberings" 3 | describe "Array Numberings" do 4 | 5 | before do 6 | @the_methods = { 7 | :second => 1, 8 | :third => 2, 9 | :fourth => 3, 10 | :fifth => 4, 11 | :sixth => 5, 12 | :seventh => 6, 13 | :eighth => 7, 14 | :ninth => 8, 15 | :tenth => 9 16 | } 17 | end 18 | 19 | it "should add array numberings" do 20 | 21 | @the_methods.keys do | method_name | 22 | Array.new.respond_to?(method_name).should == true 23 | end 24 | 25 | end 26 | 27 | it "should return the right value from each numbering" do 28 | 29 | array = (0..10).to_a 30 | 31 | @the_methods.each_pair do | method_name, index | 32 | array.send(method_name).should == array[index] 33 | end 34 | 35 | end 36 | 37 | end 38 | -------------------------------------------------------------------------------- /bin/.svn/entries: -------------------------------------------------------------------------------- 1 | 8 2 | 3 | dir 4 | 68 5 | svn+ssh://giles_bowkizzo@rubyforge.org/var/svn/utilitybelt/bin 6 | svn+ssh://giles_bowkizzo@rubyforge.org/var/svn/utilitybelt 7 | 8 | 9 | 10 | 2008-01-13T19:08:01.652704Z 11 | 56 12 | cypher 13 | 14 | 15 | svn:special svn:externals svn:needs-lock 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 624654a9-0480-469b-a93b-0723543e320f 28 | 29 | amazon 30 | file 31 | 32 | 33 | 34 | 35 | 2008-01-14T07:17:15.000000Z 36 | 1096c57014337b4c26c39ed72102fe6a 37 | 2008-01-13T19:08:01.652704Z 38 | 56 39 | cypher 40 | has-props 41 | 42 | pastie 43 | file 44 | 45 | 46 | 47 | 48 | 2008-01-14T07:17:15.000000Z 49 | 5322f742657eceef2a8ca33b1eebdd0e 50 | 2008-01-13T19:07:53.913213Z 51 | 53 52 | cypher 53 | 54 | google 55 | file 56 | 57 | 58 | 59 | 60 | 2008-01-14T07:17:15.000000Z 61 | 393ee8b6926527301b2891af39e6a9c7 62 | 2008-01-13T19:07:45.363755Z 63 | 49 64 | cypher 65 | 66 | -------------------------------------------------------------------------------- /lib/utility_belt/convertable_to_file.rb: -------------------------------------------------------------------------------- 1 | require 'tempfile' 2 | 3 | # This module adds a method, #to_file, which dumps the contents of self into a 4 | # temp file and then returns the path of that file. This is particularly useful 5 | # when calling out to shell commands which expect their input in the form of 6 | # files. 7 | # 8 | # Example: use UNIX 'diff' to compare two objects: 9 | # 10 | # >> a = ["foo", "bar", "baz"].join("\n") 11 | # => "foo\nbar\nbaz" 12 | # >> b = ["foo", "buz", "baz"].join("\n") 13 | # => "foo\nbuz\nbaz" 14 | # >> puts `diff #{a.to_file} #{b.to_file}` 15 | # 2c2 16 | # < bar 17 | # --- 18 | # > buz 19 | # => nil 20 | # 21 | module ConvertableToFile 22 | def to_file 23 | path = nil 24 | Tempfile.open(object_id.to_s) do |tempfile| 25 | tempfile << self 26 | path = tempfile.path 27 | end 28 | path 29 | end 30 | end 31 | 32 | class Object 33 | include ConvertableToFile 34 | end 35 | -------------------------------------------------------------------------------- /lib/utility_belt/language_greps.rb: -------------------------------------------------------------------------------- 1 | # fix by Bob Hutchison: 2 | class String 3 | unless public_method_defined? :blank? 4 | def blank? 5 | self !~ /\S/ 6 | end 7 | end 8 | end 9 | 10 | # TODO: upgrade these to take either regexes or strings 11 | 12 | # http://gilesbowkett.blogspot.com/2006/12/smalltalk-cleverness-translated-into.html 13 | # http://gilesbowkett.com/blog_code_samples/122906_seaside_rails/controller.txt 14 | class Object 15 | def grep_classes(search_term) 16 | classes = [] 17 | ObjectSpace.each_object {|object| classes << object.name if object.is_a? Class and not object.name.blank?} 18 | classes.find_all {|klass| klass.downcase.include? search_term.downcase} 19 | end 20 | end 21 | 22 | # http://gilesbowkett.blogspot.com/2007/11/irb-what-was-that-method-again.html 23 | class Object 24 | def grep_methods(search_term) 25 | methods.find_all {|method| method.downcase.include? search_term.downcase} 26 | end 27 | end 28 | 29 | -------------------------------------------------------------------------------- /spec/pipe_spec.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require File.join(File.dirname(__FILE__), "spec_helper") 3 | 4 | require 'spec' 5 | require 'irb' 6 | require File.join(File.dirname(__FILE__), '..', 'lib', 'utility_belt', 'pipe') 7 | 8 | describe "String#|" do 9 | before :each do 10 | @pipe = stub(:pipe, :write => nil, :close_write => nil, :read => nil) 11 | IO.stub!(:popen).and_yield(@pipe).and_return("RESULT") 12 | end 13 | 14 | it "should open a pipe" do 15 | IO.should_receive(:popen).with("COMMAND", 'r+').and_return(@pipe) 16 | "foo" | "COMMAND" 17 | end 18 | 19 | it "should write itself to the the pipe, close it, then read from it" do 20 | @pipe.should_receive(:write).with("foo").ordered 21 | @pipe.should_receive(:close_write).ordered 22 | @pipe.should_receive(:read) 23 | 24 | "foo" | "COMMAND" 25 | end 26 | 27 | it "should return the result of the IO.popen block" do 28 | ("foo" | "COMMAND").should == "RESULT" 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/convertable_to_file.rb.svn-base: -------------------------------------------------------------------------------- 1 | require 'tempfile' 2 | 3 | # This module adds a method, #to_file, which dumps the contents of self into a 4 | # temp file and then returns the path of that file. This is particularly useful 5 | # when calling out to shell commands which expect their input in the form of 6 | # files. 7 | # 8 | # Example: use UNIX 'diff' to compare two objects: 9 | # 10 | # >> a = ["foo", "bar", "baz"].join("\n") 11 | # => "foo\nbar\nbaz" 12 | # >> b = ["foo", "buz", "baz"].join("\n") 13 | # => "foo\nbuz\nbaz" 14 | # >> puts `diff #{a.to_file} #{b.to_file}` 15 | # 2c2 16 | # < bar 17 | # --- 18 | # > buz 19 | # => nil 20 | # 21 | module ConvertableToFile 22 | def to_file 23 | path = nil 24 | Tempfile.open(object_id.to_s) do |tempfile| 25 | tempfile << self 26 | path = tempfile.path 27 | end 28 | path 29 | end 30 | end 31 | 32 | class Object 33 | include ConvertableToFile 34 | end 35 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/language_greps.rb.svn-base: -------------------------------------------------------------------------------- 1 | # fix by Bob Hutchison: 2 | class String 3 | unless public_method_defined? :blank? 4 | def blank? 5 | self !~ /\S/ 6 | end 7 | end 8 | end 9 | 10 | # TODO: upgrade these to take either regexes or strings 11 | 12 | # http://gilesbowkett.blogspot.com/2006/12/smalltalk-cleverness-translated-into.html 13 | # http://gilesbowkett.com/blog_code_samples/122906_seaside_rails/controller.txt 14 | class Object 15 | def grep_classes(search_term) 16 | classes = [] 17 | ObjectSpace.each_object {|object| classes << object.name if object.is_a? Class and not object.name.blank?} 18 | classes.find_all {|klass| klass.downcase.include? search_term.downcase} 19 | end 20 | end 21 | 22 | # http://gilesbowkett.blogspot.com/2007/11/irb-what-was-that-method-again.html 23 | class Object 24 | def grep_methods(search_term) 25 | methods.find_all {|method| method.downcase.include? search_term.downcase} 26 | end 27 | end 28 | 29 | -------------------------------------------------------------------------------- /spec/.svn/text-base/pipe_spec.rb.svn-base: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require File.join(File.dirname(__FILE__), "spec_helper") 3 | 4 | require 'spec' 5 | require 'irb' 6 | require File.join(File.dirname(__FILE__), '..', 'lib', 'utility_belt', 'pipe') 7 | 8 | describe "String#|" do 9 | before :each do 10 | @pipe = stub(:pipe, :write => nil, :close_write => nil, :read => nil) 11 | IO.stub!(:popen).and_yield(@pipe).and_return("RESULT") 12 | end 13 | 14 | it "should open a pipe" do 15 | IO.should_receive(:popen).with("COMMAND", 'r+').and_return(@pipe) 16 | "foo" | "COMMAND" 17 | end 18 | 19 | it "should write itself to the the pipe, close it, then read from it" do 20 | @pipe.should_receive(:write).with("foo").ordered 21 | @pipe.should_receive(:close_write).ordered 22 | @pipe.should_receive(:read) 23 | 24 | "foo" | "COMMAND" 25 | end 26 | 27 | it "should return the result of the IO.popen block" do 28 | ("foo" | "COMMAND").should == "RESULT" 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /spec/convertable_to_file_spec.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require File.join(File.dirname(__FILE__), "spec_helper") 3 | 4 | require 'spec' 5 | require 'irb' 6 | require File.join(File.dirname(__FILE__), '..', 'lib', 'utility_belt', 'convertable_to_file') 7 | 8 | describe ConvertableToFile do 9 | include ConvertableToFile 10 | 11 | before :each do 12 | @tempfile = stub("temp file", :<< => nil, :path => nil) 13 | Tempfile.stub!(:open).and_yield(@tempfile) 14 | end 15 | 16 | it "should create a temp file using object id as basename" do 17 | should_receive(:object_id).and_return(6789) 18 | Tempfile.should_receive(:open).with("6789").and_yield(@tempfile) 19 | to_file 20 | end 21 | 22 | it "should dump self to the opened temp file" do 23 | @tempfile.should_receive(:<<).with(self) 24 | to_file 25 | end 26 | 27 | it "should return the temp file path" do 28 | @tempfile.should_receive(:path).and_return("TEMP_PATH") 29 | to_file.should == "TEMP_PATH" 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/.svn/text-base/convertable_to_file_spec.rb.svn-base: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require File.join(File.dirname(__FILE__), "spec_helper") 3 | 4 | require 'spec' 5 | require 'irb' 6 | require File.join(File.dirname(__FILE__), '..', 'lib', 'utility_belt', 'convertable_to_file') 7 | 8 | describe ConvertableToFile do 9 | include ConvertableToFile 10 | 11 | before :each do 12 | @tempfile = stub("temp file", :<< => nil, :path => nil) 13 | Tempfile.stub!(:open).and_yield(@tempfile) 14 | end 15 | 16 | it "should create a temp file using object id as basename" do 17 | should_receive(:object_id).and_return(6789) 18 | Tempfile.should_receive(:open).with("6789").and_yield(@tempfile) 19 | to_file 20 | end 21 | 22 | it "should dump self to the opened temp file" do 23 | @tempfile.should_receive(:<<).with(self) 24 | to_file 25 | end 26 | 27 | it "should return the temp file path" do 28 | @tempfile.should_receive(:path).and_return("TEMP_PATH") 29 | to_file.should == "TEMP_PATH" 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /lib/utility_belt/amazon_upload_shortcut.rb: -------------------------------------------------------------------------------- 1 | # S3 (http://amazon.rubyforge.org/) 2 | %w{aws/s3 cgi platform}.each {|lib| require lib} 3 | 4 | module UtilityBelt 5 | module AmazonUploadShortcut 6 | def aws_upload(bucket,filename) 7 | AWS::S3::Base.establish_connection!(:access_key_id => ENV['AMAZON_ACCESS_KEY_ID'], 8 | :secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY']) 9 | AWS::S3::S3Object.store(filename, open(filename), bucket, :access => :public_read) 10 | url = "http://s3.amazonaws.com/#{bucket}/#{filename}".gsub(/ /, "%20") 11 | Clipboard.write(url) if Clipboard.available? 12 | url 13 | end 14 | end 15 | end 16 | 17 | class Object 18 | include UtilityBelt::AmazonUploadShortcut 19 | end if Object.const_defined? :IRB 20 | 21 | # a quick note: the "google" command uses CGI.escape, but the URLs produced by CGI.escape 22 | # don't seem to succeed here, in practice. this may differ by OS and/or browser. Let me 23 | # know if you see something weird -- the Utility Belt mailing list is here: 24 | # 25 | # http://rubyforge.org/mailman/listinfo/utilitybelt-tinkering 26 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/amazon_upload_shortcut.rb.svn-base: -------------------------------------------------------------------------------- 1 | # S3 (http://amazon.rubyforge.org/) 2 | %w{aws/s3 cgi platform}.each {|lib| require lib} 3 | 4 | module UtilityBelt 5 | module AmazonUploadShortcut 6 | def aws_upload(bucket,filename) 7 | AWS::S3::Base.establish_connection!(:access_key_id => ENV['AMAZON_ACCESS_KEY_ID'], 8 | :secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY']) 9 | AWS::S3::S3Object.store(filename, open(filename), bucket, :access => :public_read) 10 | url = "http://s3.amazonaws.com/#{bucket}/#{filename}".gsub(/ /, "%20") 11 | Clipboard.write(url) if Clipboard.available? 12 | url 13 | end 14 | end 15 | end 16 | 17 | class Object 18 | include UtilityBelt::AmazonUploadShortcut 19 | end if Object.const_defined? :IRB 20 | 21 | # a quick note: the "google" command uses CGI.escape, but the URLs produced by CGI.escape 22 | # don't seem to succeed here, in practice. this may differ by OS and/or browser. Let me 23 | # know if you see something weird -- the Utility Belt mailing list is here: 24 | # 25 | # http://rubyforge.org/mailman/listinfo/utilitybelt-tinkering 26 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/pastie.rb.svn-base: -------------------------------------------------------------------------------- 1 | # automate creating pasties 2 | %w{platform net/http utility_belt}.each {|lib| require lib} 3 | UtilityBelt.equip(:clipboard) 4 | 5 | module UtilityBelt 6 | module Pastie 7 | def pastie(stuff_to_paste = nil) 8 | stuff_to_paste ||= Clipboard.read if Clipboard.available? 9 | # return nil unless stuff_to_paste 10 | 11 | pastie_url = Net::HTTP.post_form(URI.parse("http://pastie.caboo.se/pastes/create"), 12 | {"paste_parser" => "ruby", 13 | "paste[authorization]" => "burger", 14 | "paste[body]" => stuff_to_paste}).body.match(/href="([^\"]+)"/)[1] 15 | 16 | Clipboard.write(pastie_url) if Clipboard.available? 17 | 18 | case Platform::IMPL 19 | when :macosx 20 | Kernel.system("open #{pastie_url}") 21 | when :mswin 22 | Kernel.system("start #{pastie_url}") 23 | end 24 | 25 | return pastie_url 26 | end 27 | alias :pst :pastie 28 | end 29 | end 30 | 31 | class Object 32 | include UtilityBelt::Pastie 33 | end if Object.const_defined? :IRB 34 | -------------------------------------------------------------------------------- /lib/utility_belt/google.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | %w{rubygems platform cgi}.each {|library| require library} 3 | 4 | UtilityBelt.equip(:clipboard) 5 | 6 | module UtilityBelt 7 | module Google 8 | def google(search_term = nil) 9 | search_term ||= Clipboard.read if Clipboard.available? 10 | if search_term.empty? 11 | puts "Usage: google search_term_without_spaces (Unix command line only)" 12 | puts " google 'search term with spaces' (Unix or IRB)" 13 | puts " google (Unix or IRB)" 14 | puts " (if invoking without args, must have text in clipboard)" 15 | else 16 | url = "http://google.com/search?q=#{CGI.escape(search_term)}" 17 | case Platform::IMPL 18 | when :macosx 19 | Kernel.system("open #{url}") 20 | when :windows 21 | Kernel.system("start #{url}") 22 | #when :linux 23 | else 24 | puts "Sorry, don't know how to open an URL from the command line on your platform" 25 | end 26 | end 27 | end 28 | end 29 | end 30 | 31 | class Object 32 | include UtilityBelt::Google 33 | end if Object.const_defined? :IRB 34 | -------------------------------------------------------------------------------- /lib/utility_belt.rb: -------------------------------------------------------------------------------- 1 | # This started as my (Giles Bowkett's) .irbrc file, turned into a recipe on IRB for the Pragmatic Programmers, 2 | # and soon became a scrapbook of cool code snippets from all over the place. All the RDoc lives in the README. 3 | # Check that file for usage information, authorship, copyright, and extensive details. You can also find a 4 | # nice, HTMLified version of the README content at http://utilitybelt.rubyforge.org. 5 | 6 | UTILITY_BELT_IRB_STARTUP_PROCS = {} unless Object.const_defined? :UTILITY_BELT_IRB_STARTUP_PROCS 7 | 8 | %w{rubygems active_support utility_belt/equipper}.each {|internal_library| require internal_library} 9 | 10 | if Object.const_defined? :IRB 11 | 12 | # Called when the irb session is ready, after any external libraries have been loaded. This 13 | # allows the user to specify which gadgets in the utility belt to equip. (Kind of pushing the 14 | # metaphor, but hey, what the hell.) 15 | IRB.conf[:IRB_RC] = proc do 16 | UtilityBelt.equip(:defaults) unless UtilityBelt.equipped? 17 | UTILITY_BELT_IRB_STARTUP_PROCS.each {|symbol, proc| proc.call} 18 | end 19 | 20 | # default: dark background 21 | UtilityBelt::Themes.background(:dark) if defined? UtilityBelt::Themes 22 | end 23 | -------------------------------------------------------------------------------- /lib/utility_belt/pastie.rb: -------------------------------------------------------------------------------- 1 | # automate creating pasties 2 | %w{platform net/http utility_belt}.each {|lib| require lib} 3 | UtilityBelt.equip(:clipboard) 4 | 5 | module UtilityBelt 6 | module Pastie 7 | def pastie(stuff_to_paste = nil) 8 | stuff_to_paste ||= Clipboard.read if Clipboard.available? 9 | # return nil unless stuff_to_paste 10 | 11 | pastie_url = Net::HTTP.post_form(URI.parse("http://pastie.caboo.se/pastes/create"), 12 | {"paste_parser" => "ruby", 13 | "paste[authorization]" => "burger", 14 | "paste[body]" => stuff_to_paste}).body.match(/href="([^\"]+)"/)[1] 15 | 16 | Clipboard.write(pastie_url) if Clipboard.available? 17 | 18 | case Platform::IMPL 19 | when :macosx 20 | Kernel.system("open #{pastie_url}") 21 | when :mswin 22 | pastie_url = pastie_url.chop if pastie_url[-1].chr == "\000" 23 | Kernel.system("start #{pastie_url}") 24 | end 25 | 26 | return pastie_url 27 | end 28 | alias :pst :pastie 29 | end 30 | end 31 | 32 | class Object 33 | include UtilityBelt::Pastie 34 | end if Object.const_defined? :IRB 35 | -------------------------------------------------------------------------------- /lib/.svn/text-base/utility_belt.rb.svn-base: -------------------------------------------------------------------------------- 1 | # This started as my (Giles Bowkett's) .irbrc file, turned into a recipe on IRB for the Pragmatic Programmers, 2 | # and soon became a scrapbook of cool code snippets from all over the place. All the RDoc lives in the README. 3 | # Check that file for usage information, authorship, copyright, and extensive details. You can also find a 4 | # nice, HTMLified version of the README content at http://utilitybelt.rubyforge.org. 5 | 6 | UTILITY_BELT_IRB_STARTUP_PROCS = {} unless Object.const_defined? :UTILITY_BELT_IRB_STARTUP_PROCS 7 | 8 | %w{rubygems utility_belt/equipper}.each {|internal_library| require internal_library} 9 | 10 | if Object.const_defined? :IRB 11 | 12 | # Called when the irb session is ready, after any external libraries have been loaded. This 13 | # allows the user to specify which gadgets in the utility belt to equip. (Kind of pushing the 14 | # metaphor, but hey, what the hell.) 15 | IRB.conf[:IRB_RC] = lambda do 16 | UtilityBelt.equip(:defaults) unless UtilityBelt.equipped? 17 | UTILITY_BELT_IRB_STARTUP_PROCS.each {|symbol, proc| proc.call} 18 | end 19 | 20 | # default: dark background 21 | UtilityBelt::Themes.background(:dark) if defined? UtilityBelt::Themes 22 | end 23 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/google.rb.svn-base: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | %w{rubygems platform cgi}.each {|library| require library} 3 | 4 | UtilityBelt.equip(:clipboard) 5 | 6 | module UtilityBelt 7 | module Google 8 | def google(search_term = nil) 9 | search_term ||= Clipboard.read if Clipboard.available? 10 | if search_term.empty? 11 | puts "Usage: google search_term_without_spaces (Unix command line only)" 12 | puts " google 'search term with spaces' (Unix or IRB)" 13 | puts " google (Unix or IRB)" 14 | puts " (if invoking without args, must have text in clipboard)" 15 | else 16 | url = "http://google.com/search?q=#{CGI.escape(search_term)}" 17 | case Platform::IMPL 18 | when :macosx 19 | Kernel.system("open #{url}") 20 | when :windows 21 | Kernel.system("start #{url}") 22 | #when :linux 23 | else 24 | puts "Sorry, don't know how to open an URL from the command line on your platform" 25 | end 26 | end 27 | end 28 | end 29 | end 30 | 31 | class Object 32 | include UtilityBelt::Google 33 | end if Object.const_defined? :IRB 34 | -------------------------------------------------------------------------------- /lib/utility_belt/symbol_to_proc.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # Copyright (c) 2005 David Heinemeier Hansson 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining 5 | # a copy of this software and associated documentation files (the 6 | # "Software"), to deal in the Software without restriction, including 7 | # without limitation the rights to use, copy, modify, merge, publish, 8 | # distribute, sublicense, and/or sell copies of the Software, and to 9 | # permit persons to whom the Software is furnished to do so, subject to 10 | # the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be 13 | # included in all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | #++ 23 | 24 | class Symbol 25 | unless public_method_defined? :to_proc 26 | def to_proc 27 | Proc.new { |*args| args.shift.__send__(self, *args) } 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/symbol_to_proc.rb.svn-base: -------------------------------------------------------------------------------- 1 | #-- 2 | # Copyright (c) 2005 David Heinemeier Hansson 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining 5 | # a copy of this software and associated documentation files (the 6 | # "Software"), to deal in the Software without restriction, including 7 | # without limitation the rights to use, copy, modify, merge, publish, 8 | # distribute, sublicense, and/or sell copies of the Software, and to 9 | # permit persons to whom the Software is furnished to do so, subject to 10 | # the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be 13 | # included in all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | #++ 23 | 24 | class Symbol 25 | unless public_method_defined? :to_proc 26 | def to_proc 27 | Proc.new { |*args| args.shift.__send__(self, *args) } 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /lib/utility_belt/clipboard.rb: -------------------------------------------------------------------------------- 1 | # original clipboard code: http://project.ioni.st/post/1334#snippet_1334 2 | # turned it into a class to make it flexxy: 3 | # http://gilesbowkett.blogspot.com/2007/09/improved-auto-pastie-irb-code.html 4 | # Extended to handle windows and linux as well 5 | require 'platform' 6 | 7 | module UtilityBelt 8 | class Clipboard 9 | 10 | def self.available? 11 | @@implemented || false 12 | end 13 | 14 | case Platform::IMPL 15 | when :macosx 16 | 17 | def self.read 18 | IO.popen('pbpaste') {|clipboard| clipboard.read} 19 | end 20 | 21 | def self.write(stuff) 22 | IO.popen('pbcopy', 'w+') {|clipboard| clipboard.write(stuff)} 23 | end 24 | @@implemented = true 25 | 26 | when :mswin 27 | 28 | begin 29 | # Try loading the win32-clipboard gem 30 | require 'win32/clipboard' 31 | 32 | def self.read 33 | Win32::Clipboard.data 34 | end 35 | 36 | def self.write(stuff) 37 | Win32::Clipboard.set_data(stuff) 38 | end 39 | @@implemented = true 40 | 41 | rescue LoadError 42 | raise "You need the win32-clipboard gem for clipboard functionality!" 43 | end 44 | 45 | else 46 | raise "No suitable clipboard implementation for your platform found!" 47 | end 48 | 49 | end 50 | end 51 | 52 | Clipboard = UtilityBelt::Clipboard if Object.const_defined? :IRB 53 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/clipboard.rb.svn-base: -------------------------------------------------------------------------------- 1 | # original clipboard code: http://project.ioni.st/post/1334#snippet_1334 2 | # turned it into a class to make it flexxy: 3 | # http://gilesbowkett.blogspot.com/2007/09/improved-auto-pastie-irb-code.html 4 | # Extended to handle windows and linux as well 5 | require 'platform' 6 | 7 | module UtilityBelt 8 | class Clipboard 9 | 10 | def self.available? 11 | @@implemented || false 12 | end 13 | 14 | case Platform::IMPL 15 | when :macosx 16 | 17 | def self.read 18 | IO.popen('pbpaste') {|clipboard| clipboard.read} 19 | end 20 | 21 | def self.write(stuff) 22 | IO.popen('pbcopy', 'w+') {|clipboard| clipboard.write(stuff)} 23 | end 24 | @@implemented = true 25 | 26 | when :mswin 27 | 28 | begin 29 | # Try loading the win32-clipboard gem 30 | require 'win32/clipboard' 31 | 32 | def self.read 33 | Win32::Clipboard.data 34 | end 35 | 36 | def self.write(stuff) 37 | Win32::Clipboard.set_data(stuff) 38 | end 39 | @@implemented = true 40 | 41 | rescue LoadError 42 | raise "You need the win32-clipboard gem for clipboard functionality!" 43 | end 44 | 45 | else 46 | raise "No suitable clipboard implementation for your platform found!" 47 | end 48 | 49 | end 50 | end 51 | 52 | Clipboard = UtilityBelt::Clipboard if Object.const_defined? :IRB 53 | -------------------------------------------------------------------------------- /spec/string_to_proc_spec.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "spec_helper") 2 | require "lib/utility_belt/string_to_proc" 3 | describe "String to Proc" do 4 | 5 | before(:all) do 6 | @one2five = 1..5 7 | end 8 | 9 | it "should handle simple arrow notation" do 10 | @one2five.map(&'x -> x + 1').should eql(@one2five.map { |x| x + 1 }) 11 | @one2five.map(&'x -> x*x').should eql(@one2five.map { |x| x*x }) 12 | @one2five.inject(&'x y -> x*y').should eql(@one2five.inject { |x,y| x*y }) 13 | 'x y -> x**y'.to_proc()[2,3].should eql(proc { |x,y| x**y }[2,3]) 14 | 'y x -> x**y'.to_proc()[2,3].should eql(proc { |y,x| x**y }[2,3]) 15 | end 16 | 17 | it "should handle chained arrows" do 18 | 'x -> y -> x**y'.to_proc()[2][3].should eql(proc { |x| proc { |y| x**y } }[2][3]) 19 | 'x -> y z -> y**(z-x)'.to_proc()[1][2,3].should eql(proc { |x| proc { |y,z| y**(z-x) } }[1][2,3]) 20 | end 21 | 22 | it "should handle the default parameter" do 23 | @one2five.map(&'2**_/2').should eql(@one2five.map { |x| 2**x/2 }) 24 | @one2five.select(&'_%2==0').should eql(@one2five.select { |x| x%2==0 }) 25 | end 26 | 27 | it "should handle point-free notation" do 28 | @one2five.inject(&'*').should eql(@one2five.inject { |mem, var| mem * var }) 29 | @one2five.select(&'>2').should eql(@one2five.select { |x| x>2 }) 30 | @one2five.select(&'2<').should eql(@one2five.select { |x| 2 x + 1').should eql(@one2five.map { |x| x + 1 }) 11 | @one2five.map(&'x -> x*x').should eql(@one2five.map { |x| x*x }) 12 | @one2five.inject(&'x y -> x*y').should eql(@one2five.inject { |x,y| x*y }) 13 | 'x y -> x**y'.to_proc()[2,3].should eql(lambda { |x,y| x**y }[2,3]) 14 | 'y x -> x**y'.to_proc()[2,3].should eql(lambda { |y,x| x**y }[2,3]) 15 | end 16 | 17 | it "should handle chained arrows" do 18 | 'x -> y -> x**y'.to_proc()[2][3].should eql(lambda { |x| lambda { |y| x**y } }[2][3]) 19 | 'x -> y z -> y**(z-x)'.to_proc()[1][2,3].should eql(lambda { |x| lambda { |y,z| y**(z-x) } }[1][2,3]) 20 | end 21 | 22 | it "should handle the default parameter" do 23 | @one2five.map(&'2**_/2').should eql(@one2five.map { |x| 2**x/2 }) 24 | @one2five.select(&'_%2==0').should eql(@one2five.select { |x| x%2==0 }) 25 | end 26 | 27 | it "should handle point-free notation" do 28 | @one2five.inject(&'*').should eql(@one2five.inject { |mem, var| mem * var }) 29 | @one2five.select(&'>2').should eql(@one2five.select { |x| x>2 }) 30 | @one2five.select(&'2<').should eql(@one2five.select { |x| 2 ['is_an']) 53 | $required_libs.should == ALL_GADGETS - ['is_an'] 54 | end 55 | 56 | it "should load no gadgets except is_an" do 57 | UtilityBelt.equip(:none, :except => ['is_an']) 58 | $required_libs.should == ['is_an'] 59 | end 60 | 61 | it "should accept a string for the except-param" do 62 | UtilityBelt.equip(:none, :except => 'is_an') 63 | $required_libs.should == ['is_an'] 64 | end 65 | 66 | it "should accept a symbol for the except-param" do 67 | UtilityBelt.equip(:none, :except => :is_an) 68 | $required_libs.should == ['is_an'] 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /spec/.svn/text-base/equipper_spec.rb.svn-base: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "spec_helper") 2 | require 'lib/utility_belt/equipper' 3 | 4 | # Mocks for the gadgets 5 | UTILITY_BELT_IRB_STARTUP_PROCS = {} 6 | 7 | module IRB 8 | def self.conf 9 | {} 10 | end 11 | end 12 | 13 | describe "UtilityBelt equipper" do 14 | 15 | ALL_GADGETS = UtilityBelt::Equipper::GADGETS 16 | DEFAULT_GADGETS = UtilityBelt::Equipper::DEFAULTS 17 | 18 | before(:all) do 19 | # I know, global variables are bad, but I can't get this to work otherwise 20 | Kernel.__send__(:alias_method, :old_require, :require) 21 | Kernel.__send__(:define_method, :require, proc {|library| $required_libs << library[13..-1] }) 22 | end 23 | 24 | before(:each) do 25 | $required_libs = [] 26 | end 27 | 28 | after(:each) do 29 | $required_libs = nil 30 | end 31 | 32 | after(:all) do 33 | Kernel.__send__(:alias_method, :require, :old_require) 34 | end 35 | 36 | it "should load all gadgets" do 37 | UtilityBelt.equip(:all) 38 | $required_libs.should == ALL_GADGETS 39 | end 40 | 41 | it "should load no gadgets" do 42 | UtilityBelt.equip(:none) 43 | $required_libs.should == [] 44 | end 45 | 46 | it "should load all default gadegts" do 47 | UtilityBelt.equip(:defaults) 48 | $required_libs.should == DEFAULT_GADGETS 49 | end 50 | 51 | it "should load all gadgets except is_an" do 52 | UtilityBelt.equip(:all, :except => ['is_an']) 53 | $required_libs.should == ALL_GADGETS - ['is_an'] 54 | end 55 | 56 | it "should load no gadgets except is_an" do 57 | UtilityBelt.equip(:none, :except => ['is_an']) 58 | $required_libs.should == ['is_an'] 59 | end 60 | 61 | it "should accept a string for the except-param" do 62 | UtilityBelt.equip(:none, :except => 'is_an') 63 | $required_libs.should == ['is_an'] 64 | end 65 | 66 | it "should accept a symbol for the except-param" do 67 | UtilityBelt.equip(:none, :except => :is_an) 68 | $required_libs.should == ['is_an'] 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /utility-belt.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | s.name = "utility_belt" 3 | s.version = "1.1.1" 4 | s.author = "Giles Bowkett" 5 | s.email = "gilesb@gmail.com" 6 | s.homepage = "http://utilitybelt.rubyforge.org" 7 | s.rubyforge_project = "utility_belt" 8 | s.platform = Gem::Platform::RUBY 9 | s.summary = "A grab-bag of IRB power user madness." 10 | s.files = ["bin", "bin/amazon", "bin/google", "bin/pastie", "History.txt", "html", "html/andreas00.css", "html/authorship.html", "html/bg.gif", "html/front.jpg", "html/index.html", "html/menubg.gif", "html/menubg2.gif", "html/test.jpg", "html/usage.html", "lib", "lib/utility_belt", "lib/utility_belt/amazon_upload_shortcut.rb", "lib/utility_belt/clipboard.rb", "lib/utility_belt/command_history.rb", "lib/utility_belt/convertable_to_file.rb", "lib/utility_belt/equipper.rb", "lib/utility_belt/google.rb", "lib/utility_belt/hash_math.rb", "lib/utility_belt/interactive_editor.rb", "lib/utility_belt/irb_options.rb", "lib/utility_belt/irb_verbosity_control.rb", "lib/utility_belt/is_an.rb", "lib/utility_belt/language_greps.rb", "lib/utility_belt/not.rb", "lib/utility_belt/pastie.rb", "lib/utility_belt/pipe.rb", "lib/utility_belt/rails_finder_shortcut.rb", "lib/utility_belt/rails_verbosity_control.rb", "lib/utility_belt/string_to_proc.rb", "lib/utility_belt/symbol_to_proc.rb", "lib/utility_belt/wirble.rb", "lib/utility_belt/with.rb", "lib/utility_belt.rb", "Manifest.txt", "README", "spec", "spec/convertable_to_file_spec.rb", "spec/equipper_spec.rb", "spec/hash_math_spec.rb", "spec/interactive_editor_spec.rb", "spec/language_greps_spec.rb", "spec/pastie_spec.rb", "spec/pipe_spec.rb", "spec/spec_helper.rb", "spec/string_to_proc_spec.rb", "spec/utility_belt_spec.rb", "utility-belt.gemspec"] 11 | %w{amazon google pastie}.each do |command_line_utility| 12 | s.executables << command_line_utility 13 | end 14 | s.require_path = "lib" 15 | s.test_file = "spec/utility_belt_spec.rb" 16 | s.extra_rdoc_files = ["README"] 17 | s.add_dependency("activesupport") 18 | s.add_dependency("wirble", ">= 0.1.2") 19 | s.add_dependency("aws-s3", ">= 0.4.0") 20 | s.add_dependency("Platform", ">= 0.4.0") 21 | end 22 | -------------------------------------------------------------------------------- /lib/utility_belt/equipper.rb: -------------------------------------------------------------------------------- 1 | # Allow to select which gadgets to equip 2 | # 3 | # Author: Markus Prinz 4 | 5 | module UtilityBelt 6 | class << self 7 | def equip(*args) 8 | Equipper.equip(*args) 9 | end 10 | def equipped? 11 | Equipper.equipped? 12 | end 13 | end 14 | module Equipper 15 | GADGETS = Dir[File.join(File.dirname(__FILE__), '*.rb')].map{|file| File.basename(file)[0..-4]}.reject{|gadget| "equipper" == gadget } 16 | 17 | DEFAULTS = %w{wirble 18 | hash_math 19 | interactive_editor 20 | irb_options 21 | irb_verbosity_control} 22 | 23 | @equipped = false 24 | 25 | class << self 26 | def equip(*args) 27 | return if args.empty? 28 | 29 | gadgets_to_equip = [] 30 | 31 | # Special case using :all or :none 32 | if args[0].is_a?(Symbol) && [:all, :none, :defaults].include?(args[0]) 33 | what = args[0] 34 | 35 | unless args[1].nil? 36 | exceptions = args[1].has_key?(:except) ? args[1][:except] : [] 37 | 38 | # Handle special case where we get a string or a symbol instead of an array 39 | exceptions = exceptions.to_s.to_a unless exceptions.is_a?( Array ) 40 | else 41 | exceptions = [] 42 | end 43 | 44 | case what 45 | when :all 46 | gadgets_to_equip.push(*(GADGETS - exceptions)) 47 | when :none 48 | gadgets_to_equip.push(*exceptions) 49 | when :defaults 50 | gadgets_to_equip.push(*DEFAULTS) 51 | end 52 | # otherwise, args is a list of gadgets to equip 53 | else 54 | args.each do |arg| 55 | gadget = arg.to_s 56 | 57 | # Silently ignore unkown gadgets 58 | gadgets_to_equip << gadget if GADGETS.include? gadget 59 | end 60 | end 61 | 62 | gadgets_to_equip.each{|gadget| require "utility_belt/#{gadget}" } 63 | 64 | @equipped ||= true 65 | end 66 | def equipped? 67 | @equipped 68 | end 69 | end 70 | end 71 | end 72 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/equipper.rb.svn-base: -------------------------------------------------------------------------------- 1 | # Allow to select which gadgets to equip 2 | # 3 | # Author: Markus Prinz 4 | 5 | module UtilityBelt 6 | class << self 7 | def equip(*args) 8 | Equipper.equip(*args) 9 | end 10 | def equipped? 11 | Equipper.equipped? 12 | end 13 | end 14 | module Equipper 15 | GADGETS = Dir[File.join(File.dirname(__FILE__), '*.rb')].map{|file| File.basename(file)[0..-4]}.reject{|gadget| "equipper" == gadget } 16 | 17 | DEFAULTS = %w{wirble 18 | hash_math 19 | interactive_editor 20 | irb_options 21 | irb_verbosity_control} 22 | 23 | @equipped = false 24 | 25 | class << self 26 | def equip(*args) 27 | return if args.empty? 28 | 29 | gadgets_to_equip = [] 30 | 31 | # Special case using :all or :none 32 | if args[0].is_a?(Symbol) && [:all, :none, :defaults].include?(args[0]) 33 | what = args[0] 34 | 35 | unless args[1].nil? 36 | exceptions = args[1].has_key?(:except) ? args[1][:except] : [] 37 | 38 | # Handle special case where we get a string or a symbol instead of an array 39 | exceptions = exceptions.to_s.to_a unless exceptions.is_a?( Array ) 40 | else 41 | exceptions = [] 42 | end 43 | 44 | case what 45 | when :all 46 | gadgets_to_equip.push(*(GADGETS - exceptions)) 47 | when :none 48 | gadgets_to_equip.push(*exceptions) 49 | when :defaults 50 | gadgets_to_equip.push(*DEFAULTS) 51 | end 52 | # otherwise, args is a list of gadgets to equip 53 | else 54 | args.each do |arg| 55 | gadget = arg.to_s 56 | 57 | # Silently ignore unkown gadgets 58 | gadgets_to_equip << gadget if GADGETS.include? gadget 59 | end 60 | end 61 | 62 | gadgets_to_equip.each{|gadget| require "utility_belt/#{gadget}" } 63 | 64 | @equipped ||= true 65 | end 66 | def equipped? 67 | @equipped 68 | end 69 | end 70 | end 71 | end 72 | -------------------------------------------------------------------------------- /html/.svn/entries: -------------------------------------------------------------------------------- 1 | 8 2 | 3 | dir 4 | 68 5 | svn+ssh://giles_bowkizzo@rubyforge.org/var/svn/utilitybelt/html 6 | svn+ssh://giles_bowkizzo@rubyforge.org/var/svn/utilitybelt 7 | 8 | 9 | 10 | 2007-12-17T04:55:29.116428Z 11 | 28 12 | giles_bowkizzo 13 | 14 | 15 | svn:special svn:externals svn:needs-lock 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 624654a9-0480-469b-a93b-0723543e320f 28 | 29 | menubg.gif 30 | file 31 | 32 | 33 | 34 | 35 | 2006-09-30T03:15:46.000000Z 36 | 64462c148bd8cc5aaa2bff895ea031af 37 | 2007-12-08T17:04:46.655278Z 38 | 4 39 | giles_bowkizzo 40 | has-props 41 | 42 | menubg2.gif 43 | file 44 | 45 | 46 | 47 | 48 | 2006-09-30T03:15:48.000000Z 49 | 08c972bf2070725fb88d468d78e967be 50 | 2007-12-08T17:04:46.655278Z 51 | 4 52 | giles_bowkizzo 53 | has-props 54 | 55 | andreas00.css 56 | file 57 | 58 | 59 | 60 | 61 | 2007-12-08T17:07:55.000000Z 62 | d1b63b1a9447f7805b95f625c0d9ca83 63 | 2007-12-08T17:09:04.289781Z 64 | 5 65 | giles_bowkizzo 66 | has-props 67 | 68 | usage.html 69 | file 70 | 71 | 72 | 73 | 74 | 2007-12-17T04:54:27.000000Z 75 | 05ba52ebbaa5d8c7b525146077023c5d 76 | 2007-12-17T04:55:29.116428Z 77 | 28 78 | giles_bowkizzo 79 | has-props 80 | 81 | front.jpg 82 | file 83 | 84 | 85 | 86 | 87 | 2006-09-30T03:15:46.000000Z 88 | 88793fe00b80c59726bf724d9c865aaa 89 | 2007-12-08T17:04:46.655278Z 90 | 4 91 | giles_bowkizzo 92 | has-props 93 | 94 | authorship.html 95 | file 96 | 97 | 98 | 99 | 100 | 2007-12-16T04:34:55.000000Z 101 | 56d2f89f146b4119000f4e0b8641d14b 102 | 2007-12-16T04:35:29.683756Z 103 | 21 104 | giles_bowkizzo 105 | has-props 106 | 107 | index.html 108 | file 109 | 110 | 111 | 112 | 113 | 2007-12-16T15:22:24.000000Z 114 | 73f2597f00984576f0090400fef83aa2 115 | 2007-12-16T15:27:26.552664Z 116 | 27 117 | giles_bowkizzo 118 | has-props 119 | 120 | bg.gif 121 | file 122 | 123 | 124 | 125 | 126 | 2006-09-30T03:15:46.000000Z 127 | 6d4206d73ae0627d929172b43e92084c 128 | 2007-12-08T17:04:46.655278Z 129 | 4 130 | giles_bowkizzo 131 | has-props 132 | 133 | test.jpg 134 | file 135 | 136 | 137 | 138 | 139 | 2006-09-30T03:15:48.000000Z 140 | ab16a2d226e753b08e6acf7bd9609c9f 141 | 2007-12-08T17:04:46.655278Z 142 | 4 143 | giles_bowkizzo 144 | has-props 145 | 146 | -------------------------------------------------------------------------------- /spec/.svn/entries: -------------------------------------------------------------------------------- 1 | 8 2 | 3 | dir 4 | 68 5 | svn+ssh://giles_bowkizzo@rubyforge.org/var/svn/utilitybelt/spec 6 | svn+ssh://giles_bowkizzo@rubyforge.org/var/svn/utilitybelt 7 | 8 | 9 | 10 | 2008-02-22T16:54:56.894766Z 11 | 68 12 | avdi 13 | 14 | 15 | svn:special svn:externals svn:needs-lock 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 624654a9-0480-469b-a93b-0723543e320f 28 | 29 | language_greps_spec.rb 30 | file 31 | 32 | 33 | 34 | 35 | 2008-01-14T07:17:15.000000Z 36 | 1715306a6d24800328ff2a3c59b595cf 37 | 2008-01-14T04:37:08.337160Z 38 | 60 39 | avdi 40 | 41 | interactive_editor_spec.rb 42 | file 43 | 44 | 45 | 46 | 47 | 2008-02-09T06:15:11.000000Z 48 | f9519eb6604e469efb3c2eb29e4f0e96 49 | 2008-01-30T22:42:37.679428Z 50 | 67 51 | avdi 52 | has-props 53 | 54 | pastie_spec.rb 55 | file 56 | 57 | 58 | 59 | 60 | 2008-01-14T07:17:15.000000Z 61 | d7c061e86d93affa87b48da18f786bf2 62 | 2008-01-14T04:37:08.337160Z 63 | 60 64 | avdi 65 | 66 | convertable_to_file_spec.rb 67 | file 68 | 69 | 70 | 71 | 72 | 2008-02-22T18:17:58.000000Z 73 | f616a25f2667eae78ba1653463bd9afb 74 | 2008-02-22T16:54:56.894766Z 75 | 68 76 | avdi 77 | 78 | utility_belt_spec.rb 79 | file 80 | 81 | 82 | 83 | 84 | 2008-01-14T07:17:15.000000Z 85 | a183e2e9accc36a7c03cc100abe31e8b 86 | 2008-01-14T04:37:08.337160Z 87 | 60 88 | avdi 89 | 90 | equipper_spec.rb 91 | file 92 | 93 | 94 | 95 | 96 | 2008-01-14T07:17:15.000000Z 97 | 824499aa607d137c42f79cbc9a418aab 98 | 2008-01-14T04:37:08.337160Z 99 | 60 100 | avdi 101 | 102 | string_to_proc_spec.rb 103 | file 104 | 105 | 106 | 107 | 108 | 2008-01-14T07:17:15.000000Z 109 | 9b8c2018ba657160854778aedee01560 110 | 2008-01-14T04:37:08.337160Z 111 | 60 112 | avdi 113 | 114 | hash_math_spec.rb 115 | file 116 | 117 | 118 | 119 | 120 | 2008-01-14T07:17:15.000000Z 121 | 93f41d1b95b68acb500e55b3ccbfb838 122 | 2008-01-14T04:37:08.337160Z 123 | 60 124 | avdi 125 | 126 | pipe_spec.rb 127 | file 128 | 129 | 130 | 131 | 132 | 2008-02-09T06:15:11.000000Z 133 | 95c8713688594b0e2ab0e55902069d63 134 | 2008-01-30T22:42:37.679428Z 135 | 67 136 | avdi 137 | 138 | spec_helper.rb 139 | file 140 | 141 | 142 | 143 | 144 | 2008-01-14T07:17:15.000000Z 145 | 66d4046e338ba83c161e5135f411c3b8 146 | 2008-01-14T04:37:08.337160Z 147 | 60 148 | avdi 149 | 150 | -------------------------------------------------------------------------------- /lib/utility_belt/wirble.rb: -------------------------------------------------------------------------------- 1 | require 'wirble' 2 | Wirble.init 3 | Wirble.colorize 4 | 5 | module UtilityBelt 6 | module Themes 7 | def self.background(bkg) 8 | case bkg 9 | when :dark 10 | Wirble::Colorize.colors = UtilityBelt::Themes::WIRBLE_DEFAULT_THEME 11 | when :light 12 | Wirble::Colorize.colors = UtilityBelt::Themes::THEME_FOR_WHITE_BKG 13 | end 14 | end 15 | WIRBLE_DEFAULT_THEME = { 16 | # delimiter colors 17 | :comma => :blue, 18 | :refers => :blue, 19 | 20 | # container colors (hash and array) 21 | :open_hash => :green, 22 | :close_hash => :green, 23 | :open_array => :green, 24 | :close_array => :green, 25 | 26 | # object colors 27 | :open_object => :light_red, 28 | :object_class => :white, 29 | :object_addr_prefix => :blue, 30 | :object_line_prefix => :blue, 31 | :close_object => :light_red, 32 | 33 | # symbol colors 34 | :symbol => :yellow, 35 | :symbol_prefix => :yellow, 36 | 37 | # string colors 38 | :open_string => :red, 39 | :string => :cyan, 40 | :close_string => :red, 41 | 42 | # misc colors 43 | :number => :cyan, 44 | :keyword => :green, 45 | :class => :light_green, 46 | :range => :red, 47 | } 48 | THEME_FOR_WHITE_BKG = { 49 | # delimiter colors 50 | :comma => :purple, 51 | :refers => :blue, 52 | 53 | # container colors (hash and array) 54 | :open_hash => :red, 55 | :close_hash => :red, 56 | :open_array => :red, 57 | :close_array => :red, 58 | 59 | # object colors 60 | :open_object => :dark_gray, 61 | :object_class => :purple, 62 | :object_addr_prefix => :blue, 63 | :object_line_prefix => :blue, 64 | :close_object => :dark_gray, 65 | 66 | # symbol colors 67 | :symbol => :black, 68 | :symbol_prefix => :light_gray, 69 | 70 | # string colors 71 | :open_string => :blue, 72 | :string => :dark_gray, 73 | :close_string => :blue, 74 | 75 | # misc colors 76 | :number => :black, 77 | :keyword => :brown, 78 | :class => :red, 79 | :range => :blue, 80 | } 81 | COLORS = WIRBLE_DEFAULT_THEME 82 | end 83 | end 84 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/wirble.rb.svn-base: -------------------------------------------------------------------------------- 1 | require 'wirble' 2 | Wirble.init 3 | Wirble.colorize 4 | 5 | module UtilityBelt 6 | module Themes 7 | def self.background(bkg) 8 | case bkg 9 | when :dark 10 | Wirble::Colorize.colors = UtilityBelt::Themes::WIRBLE_DEFAULT_THEME 11 | when :light 12 | Wirble::Colorize.colors = UtilityBelt::Themes::THEME_FOR_WHITE_BKG 13 | end 14 | end 15 | WIRBLE_DEFAULT_THEME = { 16 | # delimiter colors 17 | :comma => :blue, 18 | :refers => :blue, 19 | 20 | # container colors (hash and array) 21 | :open_hash => :green, 22 | :close_hash => :green, 23 | :open_array => :green, 24 | :close_array => :green, 25 | 26 | # object colors 27 | :open_object => :light_red, 28 | :object_class => :white, 29 | :object_addr_prefix => :blue, 30 | :object_line_prefix => :blue, 31 | :close_object => :light_red, 32 | 33 | # symbol colors 34 | :symbol => :yellow, 35 | :symbol_prefix => :yellow, 36 | 37 | # string colors 38 | :open_string => :red, 39 | :string => :cyan, 40 | :close_string => :red, 41 | 42 | # misc colors 43 | :number => :cyan, 44 | :keyword => :green, 45 | :class => :light_green, 46 | :range => :red, 47 | } 48 | THEME_FOR_WHITE_BKG = { 49 | # delimiter colors 50 | :comma => :purple, 51 | :refers => :blue, 52 | 53 | # container colors (hash and array) 54 | :open_hash => :red, 55 | :close_hash => :red, 56 | :open_array => :red, 57 | :close_array => :red, 58 | 59 | # object colors 60 | :open_object => :dark_gray, 61 | :object_class => :purple, 62 | :object_addr_prefix => :blue, 63 | :object_line_prefix => :blue, 64 | :close_object => :dark_gray, 65 | 66 | # symbol colors 67 | :symbol => :black, 68 | :symbol_prefix => :light_gray, 69 | 70 | # string colors 71 | :open_string => :blue, 72 | :string => :dark_gray, 73 | :close_string => :blue, 74 | 75 | # misc colors 76 | :number => :black, 77 | :keyword => :brown, 78 | :class => :red, 79 | :range => :blue, 80 | } 81 | COLORS = WIRBLE_DEFAULT_THEME 82 | end 83 | end 84 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/interactive_editor.rb.svn-base: -------------------------------------------------------------------------------- 1 | # Giles Bowkett, Greg Brown, and several audience members from Giles' Ruby East presentation. 2 | require 'tempfile' 3 | class InteractiveEditor 4 | DEBIAN_SENSIBLE_EDITOR = "/usr/bin/sensible-editor" 5 | MACOSX_OPEN_CMD = "open" 6 | XDG_OPEN = "/usr/bin/xdg-open" 7 | 8 | def self.sensible_editor 9 | return ENV["VISUAL"] if ENV["VISUAL"] 10 | return ENV["EDITOR"] if ENV["EDITOR"] 11 | return MACOSX_OPEN_CMD if Platform::IMPL == :macosx 12 | if Platform::IMPL == :linux 13 | if File.executable?(XDG_OPEN) 14 | return XDG_OPEN 15 | end 16 | if File.executable?(DEBIAN_SENSIBLE_EDITOR) 17 | return DEBIAN_SENSIBLE_EDITOR 18 | end 19 | end 20 | raise "Could not determine what editor to use. Please specify." 21 | end 22 | 23 | attr_accessor :editor 24 | def initialize(editor = :vim) 25 | @editor = editor.to_s 26 | if @editor == "mate" 27 | @editor = "mate -w" 28 | end 29 | end 30 | def edit_interactively 31 | unless @file 32 | @file = Tempfile.new("irb_tempfile") 33 | end 34 | system("#{@editor} #{@file.path}") 35 | Object.class_eval(`cat #{@file.path}`) 36 | rescue Exception => error 37 | puts error 38 | end 39 | end 40 | 41 | module InteractiveEditing 42 | def edit_interactively(editor = InteractiveEditor.sensible_editor) 43 | unless IRB.conf[:interactive_editors] && IRB.conf[:interactive_editors][editor] 44 | IRB.conf[:interactive_editors] ||= {} 45 | IRB.conf[:interactive_editors][editor] = InteractiveEditor.new(editor) 46 | end 47 | IRB.conf[:interactive_editors][editor].edit_interactively 48 | end 49 | 50 | def handling_jruby_bug(&block) 51 | if RUBY_PLATFORM =~ /java/ 52 | puts "JRuby IRB has a bug which prevents successful IRB vi/emacs editing." 53 | puts "The JRuby team is aware of this and working on it." 54 | puts "(http://jira.codehaus.org/browse/JRUBY-2049)" 55 | else 56 | yield 57 | end 58 | end 59 | 60 | def vi 61 | handling_jruby_bug {edit_interactively(:vim)} 62 | end 63 | 64 | def mate 65 | edit_interactively(:mate) 66 | end 67 | 68 | # TODO: Hardcore Emacs users use emacsclient or gnuclient to open documents in 69 | # their existing sessions, rather than starting a brand new Emacs process. 70 | def emacs 71 | handling_jruby_bug {edit_interactively(:emacs)} 72 | end 73 | end 74 | 75 | # Since we only intend to use this from the IRB command line, I see no reason to 76 | # extend the entire Object class with this module when we can just extend the 77 | # IRB main object. 78 | self.extend InteractiveEditing if Object.const_defined? :IRB 79 | -------------------------------------------------------------------------------- /lib/utility_belt/interactive_editor.rb: -------------------------------------------------------------------------------- 1 | # Giles Bowkett, Greg Brown, and several audience members from Giles' Ruby East presentation. 2 | require 'tempfile' 3 | class InteractiveEditor 4 | DEBIAN_SENSIBLE_EDITOR = "/usr/bin/sensible-editor" 5 | MACOSX_OPEN_CMD = "open" 6 | XDG_OPEN = "/usr/bin/xdg-open" 7 | 8 | def self.sensible_editor 9 | return ENV["VISUAL"] if ENV["VISUAL"] 10 | return ENV["EDITOR"] if ENV["EDITOR"] 11 | return MACOSX_OPEN_CMD if Platform::IMPL == :macosx 12 | if Platform::IMPL == :linux 13 | if File.executable?(XDG_OPEN) 14 | return XDG_OPEN 15 | end 16 | if File.executable?(DEBIAN_SENSIBLE_EDITOR) 17 | return DEBIAN_SENSIBLE_EDITOR 18 | end 19 | end 20 | raise "Could not determine what editor to use. Please specify." 21 | end 22 | 23 | attr_accessor :editor 24 | def initialize(editor = :vim) 25 | @editor = editor.to_s 26 | if @editor == "mate" 27 | @editor = "mate -w" 28 | end 29 | end 30 | def edit_interactively 31 | unless @file 32 | @file = Tempfile.new(["irb_tempfile", ".rb"]) 33 | end 34 | system("#{@editor} #{@file.path}") 35 | Object.class_eval(`cat #{@file.path}`) 36 | rescue Exception => error 37 | puts error 38 | end 39 | end 40 | 41 | module InteractiveEditing 42 | def edit_interactively(editor = InteractiveEditor.sensible_editor) 43 | unless IRB.conf[:interactive_editors] && IRB.conf[:interactive_editors][editor] 44 | IRB.conf[:interactive_editors] ||= {} 45 | IRB.conf[:interactive_editors][editor] = InteractiveEditor.new(editor) 46 | end 47 | IRB.conf[:interactive_editors][editor].edit_interactively 48 | end 49 | 50 | def handling_jruby_bug(&block) 51 | if RUBY_PLATFORM =~ /java/ 52 | puts "JRuby IRB has a bug which prevents successful IRB vi/emacs editing." 53 | puts "The JRuby team is aware of this and working on it. But it might be unfixable." 54 | puts "(http://jira.codehaus.org/browse/JRUBY-2049)" 55 | else 56 | yield 57 | end 58 | end 59 | 60 | def vi 61 | handling_jruby_bug {edit_interactively(:vim)} 62 | end 63 | 64 | def mate 65 | edit_interactively(:mate) 66 | end 67 | 68 | # TODO: Hardcore Emacs users use emacsclient or gnuclient to open documents in 69 | # their existing sessions, rather than starting a brand new Emacs process. 70 | def emacs 71 | handling_jruby_bug {edit_interactively(:emacs)} 72 | end 73 | end 74 | 75 | # Since we only intend to use this from the IRB command line, I see no reason to 76 | # extend the entire Object class with this module when we can just extend the 77 | # IRB main object. 78 | self.extend InteractiveEditing if Object.const_defined? :IRB 79 | -------------------------------------------------------------------------------- /lib/utility_belt/string_to_proc.rb: -------------------------------------------------------------------------------- 1 | # String#to_proc 2 | # 3 | # See http://weblog.raganwald.com/2007/10/stringtoproc.html 4 | # 5 | # Ported from the String Lambdas in Oliver Steele's Functional Javascript 6 | # http://osteele.com/sources/javascript/functional/ 7 | # 8 | # This work is licensed under the MIT License: 9 | # 10 | # (c) 2007 Reginald Braithwaite 11 | # Portions Copyright (c) 2006 Oliver Steele 12 | # 13 | # Permission is hereby granted, free of charge, to any person obtaining 14 | # a copy of this software and associated documentation files (the 15 | # "Software"), to deal in the Software without restriction, including 16 | # without limitation the rights to use, copy, modify, merge, publish, 17 | # distribute, sublicense, and/or sell copies of the Software, and to 18 | # permit persons to whom the Software is furnished to do so, subject to 19 | # the following conditions: 20 | # 21 | # The above copyright notice and this permission notice shall be 22 | # included in all copies or substantial portions of the Software. 23 | # 24 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 | 32 | class String 33 | unless public_method_defined? :to_proc 34 | def to_proc &block 35 | params = [] 36 | expr = self 37 | sections = expr.split(/\s*->\s*/m) 38 | if sections.length > 1 then 39 | eval_block(sections.reverse!.inject { |e, p| "(Proc.new { |#{p.split(/\s/).join(', ')}| #{e} })" }, block) 40 | elsif expr.match(/\b_\b/) 41 | eval_block("Proc.new { |_| #{expr} }", block) 42 | else 43 | leftSection = expr.match(/^\s*(?:[+*\/%&|\^\.=<>\[]|!=)/m) 44 | rightSection = expr.match(/[+\-*\/%&|\^\.=<>!]\s*$/m) 45 | if leftSection || rightSection then 46 | if (leftSection) then 47 | params.push('$left') 48 | expr = '$left' + expr 49 | end 50 | if (rightSection) then 51 | params.push('$right') 52 | expr = expr + '$right' 53 | end 54 | else 55 | self.gsub( 56 | /(?:\b[A-Z]|\.[a-zA-Z_$])[a-zA-Z_$\d]*|[a-zA-Z_$][a-zA-Z_$\d]*:|self|arguments|'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"/, '' 57 | ).scan( 58 | /([a-z_$][a-z_$\d]*)/i 59 | ) do |v| 60 | params.push(v) unless params.include?(v) 61 | end 62 | end 63 | eval_block("Proc.new { |#{params.join(', ')}| #{expr} }", block) 64 | end 65 | end 66 | private 67 | def eval_block(code, block) 68 | eval code, block && block.binding 69 | end 70 | end 71 | end 72 | 73 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/string_to_proc.rb.svn-base: -------------------------------------------------------------------------------- 1 | # String#to_proc 2 | # 3 | # See http://weblog.raganwald.com/2007/10/stringtoproc.html 4 | # 5 | # Ported from the String Lambdas in Oliver Steele's Functional Javascript 6 | # http://osteele.com/sources/javascript/functional/ 7 | # 8 | # This work is licensed under the MIT License: 9 | # 10 | # (c) 2007 Reginald Braithwaite 11 | # Portions Copyright (c) 2006 Oliver Steele 12 | # 13 | # Permission is hereby granted, free of charge, to any person obtaining 14 | # a copy of this software and associated documentation files (the 15 | # "Software"), to deal in the Software without restriction, including 16 | # without limitation the rights to use, copy, modify, merge, publish, 17 | # distribute, sublicense, and/or sell copies of the Software, and to 18 | # permit persons to whom the Software is furnished to do so, subject to 19 | # the following conditions: 20 | # 21 | # The above copyright notice and this permission notice shall be 22 | # included in all copies or substantial portions of the Software. 23 | # 24 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 | 32 | class String 33 | unless public_method_defined? :to_proc 34 | def to_proc &block 35 | params = [] 36 | expr = self 37 | sections = expr.split(/\s*->\s*/m) 38 | if sections.length > 1 then 39 | eval_block(sections.reverse!.inject { |e, p| "(Proc.new { |#{p.split(/\s/).join(', ')}| #{e} })" }, block) 40 | elsif expr.match(/\b_\b/) 41 | eval_block("Proc.new { |_| #{expr} }", block) 42 | else 43 | leftSection = expr.match(/^\s*(?:[+*\/%&|\^\.=<>\[]|!=)/m) 44 | rightSection = expr.match(/[+\-*\/%&|\^\.=<>!]\s*$/m) 45 | if leftSection || rightSection then 46 | if (leftSection) then 47 | params.push('$left') 48 | expr = '$left' + expr 49 | end 50 | if (rightSection) then 51 | params.push('$right') 52 | expr = expr + '$right' 53 | end 54 | else 55 | self.gsub( 56 | /(?:\b[A-Z]|\.[a-zA-Z_$])[a-zA-Z_$\d]*|[a-zA-Z_$][a-zA-Z_$\d]*:|self|arguments|'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"/, '' 57 | ).scan( 58 | /([a-z_$][a-z_$\d]*)/i 59 | ) do |v| 60 | params.push(v) unless params.include?(v) 61 | end 62 | end 63 | eval_block("Proc.new { |#{params.join(', ')}| #{expr} }", block) 64 | end 65 | end 66 | private 67 | def eval_block(code, block) 68 | eval code, block && block.binding 69 | end 70 | end 71 | end 72 | 73 | -------------------------------------------------------------------------------- /lib/utility_belt/command_history.rb: -------------------------------------------------------------------------------- 1 | # history 2 | # http://blog.bleything.net/pages 3 | # http://gilesbowkett.blogspot.com/2007/06/irbrc-modifications.html 4 | # Ben's history stuff, slightly modified, plus hvi method 5 | 6 | 7 | 8 | # Adds shell-style history display and replay to irb. The magic happens in 9 | # the h, h!, and hw methods. 10 | # 11 | # == Authors 12 | # 13 | # * Ben Bleything 14 | # 15 | # == Copyright 16 | # 17 | # Copyright (c) 2007 Ben Bleything 18 | # 19 | # This code released under the terms of the BSD license. 20 | # 21 | # == Version 22 | # 23 | # $Id: history.rb 50 2007-07-30 18:55:09Z ben $ 24 | # 25 | 26 | require 'tempfile' 27 | 28 | class Object 29 | def history(how_many = 50) 30 | history_size = Readline::HISTORY.size 31 | # no lines, get out of here 32 | puts "No history" and return if history_size == 0 33 | start_index = 0 34 | # not enough lines, only show what we have 35 | if history_size <= how_many 36 | how_many = history_size - 1 37 | end_index = how_many 38 | else 39 | end_index = history_size - 1 # -1 to adjust for array offset 40 | start_index = end_index - how_many 41 | end 42 | start_index.upto(end_index) {|i| print_line i} 43 | end 44 | alias :h :history 45 | 46 | # -2 because -1 is ourself 47 | def history_do(lines = (Readline::HISTORY.size - 2)) 48 | irb_eval lines 49 | end 50 | alias :h! :history_do 51 | 52 | def history_write(filename, lines) 53 | file = File.open(filename, 'w') 54 | get_lines(lines).each do |l| 55 | file << "#{l}\n" 56 | end 57 | file.close 58 | end 59 | 60 | # hack to handle JRuby bug 61 | def handling_jruby_bug(&block) 62 | if RUBY_PLATFORM =~ /java/ 63 | puts "JRuby IRB has a bug which prevents successful IRB vi interoperation." 64 | puts "The JRuby team is aware of this and working on it." 65 | puts "(http://jira.codehaus.org/browse/JRUBY-2049)" 66 | else 67 | yield 68 | end 69 | end 70 | 71 | # TODO: history_write should go to a file, or the clipboard, or a file which opens in an application 72 | def history_to_vi 73 | handling_jruby_bug do 74 | file = Tempfile.new("irb_tempfile") 75 | get_lines(0..(Readline::HISTORY.size - 1)).each do |line| 76 | file << "#{line}\n" 77 | end 78 | file.close 79 | system("vim #{file.path}") 80 | end 81 | end 82 | alias :hvi :history_to_vi 83 | 84 | private 85 | def get_line(line_number) 86 | Readline::HISTORY[line_number] rescue "" 87 | end 88 | 89 | def get_lines(lines = []) 90 | return [get_line(lines)] if lines.is_a? Fixnum 91 | out = [] 92 | lines = lines.to_a if lines.is_a? Range 93 | lines.each do |l| 94 | out << Readline::HISTORY[l] 95 | end 96 | out 97 | end 98 | 99 | def print_line(line_number, show_line_numbers = true) 100 | print line_number.to_s + ": " if show_line_numbers 101 | puts get_line(line_number) 102 | end 103 | 104 | def irb_eval(lines) 105 | to_eval = get_lines(lines) 106 | to_eval.each {|l| Readline::HISTORY << l} 107 | eval to_eval.join("\n") 108 | end 109 | end 110 | 111 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/text-base/command_history.rb.svn-base: -------------------------------------------------------------------------------- 1 | # history 2 | # http://blog.bleything.net/pages 3 | # http://gilesbowkett.blogspot.com/2007/06/irbrc-modifications.html 4 | # Ben's history stuff, slightly modified, plus hvi method 5 | 6 | 7 | 8 | # Adds shell-style history display and replay to irb. The magic happens in 9 | # the h, h!, and hw methods. 10 | # 11 | # == Authors 12 | # 13 | # * Ben Bleything 14 | # 15 | # == Copyright 16 | # 17 | # Copyright (c) 2007 Ben Bleything 18 | # 19 | # This code released under the terms of the BSD license. 20 | # 21 | # == Version 22 | # 23 | # $Id: history.rb 50 2007-07-30 18:55:09Z ben $ 24 | # 25 | 26 | require 'tempfile' 27 | 28 | class Object 29 | def history(how_many = 50) 30 | history_size = Readline::HISTORY.size 31 | # no lines, get out of here 32 | puts "No history" and return if history_size == 0 33 | start_index = 0 34 | # not enough lines, only show what we have 35 | if history_size <= how_many 36 | how_many = history_size - 1 37 | end_index = how_many 38 | else 39 | end_index = history_size - 1 # -1 to adjust for array offset 40 | start_index = end_index - how_many 41 | end 42 | start_index.upto(end_index) {|i| print_line i} 43 | end 44 | alias :h :history 45 | 46 | # -2 because -1 is ourself 47 | def history_do(lines = (Readline::HISTORY.size - 2)) 48 | irb_eval lines 49 | end 50 | alias :h! :history_do 51 | 52 | def history_write(filename, lines) 53 | file = File.open(filename, 'w') 54 | get_lines(lines).each do |l| 55 | file << "#{l}\n" 56 | end 57 | file.close 58 | end 59 | 60 | # hack to handle JRuby bug 61 | def handling_jruby_bug(&block) 62 | if RUBY_PLATFORM =~ /java/ 63 | puts "JRuby IRB has a bug which prevents successful IRB vi interoperation." 64 | puts "The JRuby team is aware of this and working on it." 65 | puts "(http://jira.codehaus.org/browse/JRUBY-2049)" 66 | else 67 | yield 68 | end 69 | end 70 | 71 | # TODO: history_write should go to a file, or the clipboard, or a file which opens in an application 72 | def history_to_vi 73 | handling_jruby_bug do 74 | file = Tempfile.new("irb_tempfile") 75 | get_lines(0..(Readline::HISTORY.size - 1)).each do |line| 76 | file << "#{line}\n" 77 | end 78 | file.close 79 | system("vim #{file.path}") 80 | end 81 | end 82 | alias :hvi :history_to_vi 83 | 84 | private 85 | def get_line(line_number) 86 | Readline::HISTORY[line_number] rescue "" 87 | end 88 | 89 | def get_lines(lines = []) 90 | return [get_line(lines)] if lines.is_a? Fixnum 91 | out = [] 92 | lines = lines.to_a if lines.is_a? Range 93 | lines.each do |l| 94 | out << Readline::HISTORY[l] 95 | end 96 | out 97 | end 98 | 99 | def print_line(line_number, show_line_numbers = true) 100 | print line_number.to_s + ": " if show_line_numbers 101 | puts get_line(line_number) 102 | end 103 | 104 | def irb_eval(lines) 105 | to_eval = get_lines(lines) 106 | to_eval.each {|l| Readline::HISTORY << l} 107 | eval to_eval.join("\n") 108 | end 109 | end 110 | 111 | -------------------------------------------------------------------------------- /spec/pastie_spec.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "spec_helper") 2 | require 'rubygems' 3 | gem 'rspec' 4 | require 'spec' 5 | Platform = Module.new unless Object.const_defined?('Platform') 6 | Net = Module.new unless Object.const_defined?('Net') 7 | 8 | require File.expand_path(File.join(File.dirname(__FILE__),'..','lib/utility_belt')) 9 | UtilityBelt.equip(:pastie) 10 | include UtilityBelt::Pastie 11 | Clipboard = UtilityBelt::Clipboard unless Object.const_defined?('Clipboard') 12 | 13 | describe "pastie being called" do 14 | 15 | before(:all) do 16 | Net::HTTP = mock('HTTP') unless Net.const_defined?('HTTP') 17 | URI = mock('URI') unless Object.const_defined?('URI') 18 | Clipboard = mock('clipboard') unless Object.const_defined?('Clipboard') 19 | end 20 | 21 | before(:each) do 22 | @page = mock('page') 23 | @page.stub!(:body).and_return('href="foo"') 24 | Net::HTTP.stub!(:post_form).and_return(@page) 25 | URI.stub!(:parse) 26 | Clipboard.stub!(:read) 27 | Clipboard.stub!(:write) 28 | Kernel.stub!(:system) 29 | end 30 | 31 | it "should be available in global namespace and not blow-up with default stub/mocking" do 32 | pastie 33 | end 34 | 35 | it "should uri-parse the pastie uri" do 36 | URI.should_receive(:parse).with("http://pastie.caboo.se/pastes/create") 37 | pastie 38 | end 39 | 40 | it "should pass the uri-parsed result into the post" do 41 | URI.should_receive(:parse).and_return('a_uri_object') 42 | Net::HTTP.should_receive(:post_form).with('a_uri_object', anything()).and_return(@page) 43 | pastie 44 | end 45 | 46 | it "should call system open on the pastie return" do 47 | @page.should_receive(:body).and_return('href="returned_url"') 48 | case Platform::IMPL 49 | when :macosx 50 | Kernel.should_receive(:system).with("open returned_url") 51 | when :mswin 52 | Kernel.should_receive(:system).with("start returned_url") 53 | end 54 | pastie 55 | end 56 | 57 | it "should write resulting url into the clipboard" do 58 | @page.should_receive(:body).and_return('href="returned_url"') 59 | Clipboard.should_receive(:write).with('returned_url') 60 | pastie 61 | end 62 | 63 | describe "with no parameter it uses the clipboard" do 64 | it "should read the clipboard" do 65 | Clipboard.should_receive(:read) 66 | pastie 67 | end 68 | 69 | it "should put the clipboard results in the post to pastie" do 70 | Clipboard.should_receive(:read).and_return('bar') 71 | Net::HTTP.should_receive(:post_form).with(anything(),{"paste_parser" => "ruby", 72 | "paste[authorization]" => "burger", 73 | "paste[body]" => 'bar'}).and_return(@page) 74 | pastie 75 | end 76 | end 77 | 78 | describe "with a parameter instead" do 79 | #TODO: windows/linux safer now, since no clipboard functionality? 80 | it "should not even read the clipboard" do 81 | Clipboard.should_not_receive(:read) 82 | pastie "baz" 83 | end 84 | 85 | it "should pass in the parameter instead" do 86 | Net::HTTP.should_receive(:post_form).with(anything(),{"paste_parser" => "ruby", 87 | "paste[authorization]" => "burger", 88 | "paste[body]" => 'baz'}).and_return(@page) 89 | pastie "baz" 90 | end 91 | end 92 | end 93 | -------------------------------------------------------------------------------- /spec/.svn/text-base/pastie_spec.rb.svn-base: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "spec_helper") 2 | require 'rubygems' 3 | gem 'rspec' 4 | require 'spec' 5 | Platform = Module.new unless Object.const_defined?('Platform') 6 | Net = Module.new unless Object.const_defined?('Net') 7 | 8 | require File.expand_path(File.join(File.dirname(__FILE__),'..','lib/utility_belt')) 9 | UtilityBelt.equip(:pastie) 10 | include UtilityBelt::Pastie 11 | Clipboard = UtilityBelt::Clipboard unless Object.const_defined?('Clipboard') 12 | 13 | describe "pastie being called" do 14 | 15 | before(:all) do 16 | Net::HTTP = mock('HTTP') unless Net.const_defined?('HTTP') 17 | URI = mock('URI') unless Object.const_defined?('URI') 18 | Clipboard = mock('clipboard') unless Object.const_defined?('Clipboard') 19 | end 20 | 21 | before(:each) do 22 | @page = mock('page') 23 | @page.stub!(:body).and_return('href="foo"') 24 | Net::HTTP.stub!(:post_form).and_return(@page) 25 | URI.stub!(:parse) 26 | Clipboard.stub!(:read) 27 | Clipboard.stub!(:write) 28 | Kernel.stub!(:system) 29 | end 30 | 31 | it "should be available in global namespace and not blow-up with default stub/mocking" do 32 | pastie 33 | end 34 | 35 | it "should uri-parse the pastie uri" do 36 | URI.should_receive(:parse).with("http://pastie.caboo.se/pastes/create") 37 | pastie 38 | end 39 | 40 | it "should pass the uri-parsed result into the post" do 41 | URI.should_receive(:parse).and_return('a_uri_object') 42 | Net::HTTP.should_receive(:post_form).with('a_uri_object', anything()).and_return(@page) 43 | pastie 44 | end 45 | 46 | it "should call system open on the pastie return" do 47 | @page.should_receive(:body).and_return('href="returned_url"') 48 | case Platform::IMPL 49 | when :macosx 50 | Kernel.should_receive(:system).with("open returned_url") 51 | when :mswin 52 | Kernel.should_receive(:system).with("start returned_url") 53 | end 54 | pastie 55 | end 56 | 57 | it "should write resulting url into the clipboard" do 58 | @page.should_receive(:body).and_return('href="returned_url"') 59 | Clipboard.should_receive(:write).with('returned_url') 60 | pastie 61 | end 62 | 63 | describe "with no parameter it uses the clipboard" do 64 | it "should read the clipboard" do 65 | Clipboard.should_receive(:read) 66 | pastie 67 | end 68 | 69 | it "should put the clipboard results in the post to pastie" do 70 | Clipboard.should_receive(:read).and_return('bar') 71 | Net::HTTP.should_receive(:post_form).with(anything(),{"paste_parser" => "ruby", 72 | "paste[authorization]" => "burger", 73 | "paste[body]" => 'bar'}).and_return(@page) 74 | pastie 75 | end 76 | end 77 | 78 | describe "with a parameter instead" do 79 | #TODO: windows/linux safer now, since no clipboard functionality? 80 | it "should not even read the clipboard" do 81 | Clipboard.should_not_receive(:read) 82 | pastie "baz" 83 | end 84 | 85 | it "should pass in the parameter instead" do 86 | Net::HTTP.should_receive(:post_form).with(anything(),{"paste_parser" => "ruby", 87 | "paste[authorization]" => "burger", 88 | "paste[body]" => 'baz'}).and_return(@page) 89 | pastie "baz" 90 | end 91 | end 92 | end 93 | -------------------------------------------------------------------------------- /html/index.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Utility Belt 11 | 12 | 13 | 14 |
15 | 19 | 20 |
21 |

Site menu:

22 | 28 | 29 |
30 | 31 |
32 |

Installation And Overview

33 | 34 |

Utility Belt is a grab-bag of tricks, tools, techniques, trifles, and toys for IRB, including convenience methods, language patches, and useful extensions. It also includes a couple command-line widgets. Its primary inspirations were an awesome gem called Wirble and a blog post by Amy Hoy called "Secrets Of The Rails Console Ninjas".

35 | 36 |

INSTALL

37 | 38 |

sudo gem install utility_belt

39 | 40 |

FEATURES

41 | 42 |
    43 |
  • Interactively edit IRB code in your preferred text editor
  • 44 |
  • Read from and write to OS X clipboard
  • 45 |
  • Post your code to Pastie with one command (OS X only)
  • 46 |
  • Kick-ass Unix-style history buffer
  • 47 |
  • Write command history to file or vi
  • 48 |
  • Grep classes and methods for strings
  • 49 |
  • Verbosity controls for regular IRB and Rails console
  • 50 |
  • Finder shortcuts for Rails console
  • 51 |
  • Upload shortcut for Amazon S3
  • 52 |
  • Command-line Amazon S3 upload script
  • 53 |
  • Command-line Google shortcut (OS X only)
  • 54 |
  • Auto-indentation
  • 55 |
  • _ special variable (like Unix shell var !!)
  • 56 |
  • Extremely basic themes for Wirble syntax coloring
  • 57 |
  • Pascal/JavaScript-style "with" statement
  • 58 |
  • String#to_proc
  • 59 |
  • Add and subtract Hashes with + and -
  • 60 |
  • Grammatically-correct is_an? method - no more "is_a? Array" statements
  • 61 |
  • One-character exit command
  • 62 |
63 | 64 |

REQUIREMENTS

65 | 66 |
    67 |
  • ReadLine
  • 68 |
  • Wirble
  • 69 |
  • Amazon S3
  • 70 |
  • Platform
  • 71 |
  • Some features require OS X
  • 72 |
73 | 74 |
75 | 76 | 79 |
80 | 81 | 82 | -------------------------------------------------------------------------------- /html/.svn/text-base/index.html.svn-base: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Utility Belt 11 | 12 | 13 | 14 |
15 | 19 | 20 |
21 |

Site menu:

22 | 28 | 29 |
30 | 31 |
32 |

Installation And Overview

33 | 34 |

Utility Belt is a grab-bag of tricks, tools, techniques, trifles, and toys for IRB, including convenience methods, language patches, and useful extensions. It also includes a couple command-line widgets. Its primary inspirations were an awesome gem called Wirble and a blog post by Amy Hoy called "Secrets Of The Rails Console Ninjas".

35 | 36 |

INSTALL

37 | 38 |

sudo gem install utility_belt

39 | 40 |

FEATURES

41 | 42 |
    43 |
  • Interactively edit IRB code in your preferred text editor
  • 44 |
  • Read from and write to OS X clipboard
  • 45 |
  • Post your code to Pastie with one command (OS X only)
  • 46 |
  • Kick-ass Unix-style history buffer
  • 47 |
  • Write command history to file or vi
  • 48 |
  • Grep classes and methods for strings
  • 49 |
  • Verbosity controls for regular IRB and Rails console
  • 50 |
  • Finder shortcuts for Rails console
  • 51 |
  • Upload shortcut for Amazon S3
  • 52 |
  • Command-line Amazon S3 upload script
  • 53 |
  • Command-line Google shortcut (OS X only)
  • 54 |
  • Auto-indentation
  • 55 |
  • _ special variable (like Unix shell var !!)
  • 56 |
  • Extremely basic themes for Wirble syntax coloring
  • 57 |
  • Pascal/JavaScript-style "with" statement
  • 58 |
  • String#to_proc
  • 59 |
  • Add and subtract Hashes with + and -
  • 60 |
  • Grammatically-correct is_an? method - no more "is_a? Array" statements
  • 61 |
  • One-character exit command
  • 62 |
63 | 64 |

REQUIREMENTS

65 | 66 |
    67 |
  • ReadLine
  • 68 |
  • Wirble
  • 69 |
  • Amazon S3
  • 70 |
  • Platform
  • 71 |
  • Some features require OS X
  • 72 |
73 | 74 |
75 | 76 | 79 |
80 | 81 | 82 | -------------------------------------------------------------------------------- /lib/utility_belt/.svn/entries: -------------------------------------------------------------------------------- 1 | 8 2 | 3 | dir 4 | 68 5 | svn+ssh://giles_bowkizzo@rubyforge.org/var/svn/utilitybelt/lib/utility_belt 6 | svn+ssh://giles_bowkizzo@rubyforge.org/var/svn/utilitybelt 7 | 8 | 9 | 10 | 2008-02-22T16:54:56.894766Z 11 | 68 12 | avdi 13 | 14 | 15 | svn:special svn:externals svn:needs-lock 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 624654a9-0480-469b-a93b-0723543e320f 28 | 29 | rails_verbosity_control.rb 30 | file 31 | 32 | 33 | 34 | 35 | 2008-01-14T07:17:14.000000Z 36 | fd78c9429589badb7286e5ab6a2783b3 37 | 2008-01-08T23:09:16.531198Z 38 | 38 39 | cypher 40 | 41 | irb_verbosity_control.rb 42 | file 43 | 44 | 45 | 46 | 47 | 2008-01-14T07:17:14.000000Z 48 | 64a2d892397a3c57138c8ae5edfe1c79 49 | 2008-01-08T23:09:16.531198Z 50 | 38 51 | cypher 52 | 53 | language_greps.rb 54 | file 55 | 56 | 57 | 58 | 59 | 2008-01-14T07:17:14.000000Z 60 | 1c61c655634ffd56d40db504da9fce2c 61 | 2008-01-08T23:09:16.531198Z 62 | 38 63 | cypher 64 | 65 | interactive_editor.rb 66 | file 67 | 68 | 69 | 70 | 71 | 2008-01-29T21:52:18.000000Z 72 | 78167e0a799370d4deb88d9c11b0f647 73 | 2008-01-29T21:52:40.513521Z 74 | 66 75 | giles_bowkizzo 76 | 77 | amazon_upload_shortcut.rb 78 | file 79 | 80 | 81 | 82 | 83 | 2008-01-14T07:17:14.000000Z 84 | 6cf6ef82f3de58346fbcb5dec6b9f8a8 85 | 2008-01-13T19:08:01.652704Z 86 | 56 87 | cypher 88 | 89 | wirble.rb 90 | file 91 | 92 | 93 | 94 | 95 | 2008-01-29T21:30:37.000000Z 96 | 97423ffcedc8d9ded77ec2962386a111 97 | 2008-01-14T09:29:25.126243Z 98 | 61 99 | cypher 100 | 101 | pastie.rb 102 | file 103 | 104 | 105 | 106 | 107 | 2008-01-14T07:17:14.000000Z 108 | 6a64a5054b115eb57dbc10ed1c6b8ebd 109 | 2008-01-13T19:07:51.528875Z 110 | 52 111 | cypher 112 | 113 | irb_options.rb 114 | file 115 | 116 | 117 | 118 | 119 | 2008-01-14T07:17:14.000000Z 120 | 926c0aa718b9093a7bb8b15f89ac913e 121 | 2008-01-08T23:09:16.531198Z 122 | 38 123 | cypher 124 | 125 | is_an.rb 126 | file 127 | 128 | 129 | 130 | 131 | 2008-01-14T07:17:14.000000Z 132 | 9424e26c971d49b5b6c1becc10bcfe50 133 | 2008-01-08T23:09:16.531198Z 134 | 38 135 | cypher 136 | 137 | equipper.rb 138 | file 139 | 140 | 141 | 142 | 143 | 2008-01-29T21:30:37.000000Z 144 | b93a7e73b617d900e65c6293c02f6ddb 145 | 2008-01-15T21:12:14.565159Z 146 | 64 147 | cypher 148 | 149 | symbol_to_proc.rb 150 | file 151 | 152 | 153 | 154 | 155 | 2008-01-14T07:17:14.000000Z 156 | d3ea9378a91fa48965cf6e17f93fcab9 157 | 2008-01-08T23:09:16.531198Z 158 | 38 159 | cypher 160 | 161 | string_to_proc.rb 162 | file 163 | 164 | 165 | 166 | 167 | 2008-01-14T07:17:14.000000Z 168 | 6ad47c7e2395ba4b523d21080d794a33 169 | 2008-01-08T23:09:16.531198Z 170 | 38 171 | cypher 172 | 173 | rails_finder_shortcut.rb 174 | file 175 | 176 | 177 | 178 | 179 | 2008-01-14T07:17:14.000000Z 180 | 03ccb44cec22e3fe686a5698c761ec95 181 | 2008-01-08T23:09:16.531198Z 182 | 38 183 | cypher 184 | 185 | hash_math.rb 186 | file 187 | 188 | 189 | 190 | 191 | 2008-01-14T07:17:14.000000Z 192 | 84de8aa378e0b72f8cf23636b60bd0d0 193 | 2008-01-08T23:09:16.531198Z 194 | 38 195 | cypher 196 | 197 | pipe.rb 198 | file 199 | 200 | 201 | 202 | 203 | 2008-02-09T06:15:11.000000Z 204 | e9d900d19758b094272bfc0461f04a01 205 | 2008-01-30T22:42:37.679428Z 206 | 67 207 | avdi 208 | 209 | command_history.rb 210 | file 211 | 212 | 213 | 214 | 215 | 2008-01-29T21:52:13.000000Z 216 | ba05333cf4d74c29a28b7ea182f84fe0 217 | 2008-01-29T21:52:40.513521Z 218 | 66 219 | giles_bowkizzo 220 | 221 | clipboard.rb 222 | file 223 | 224 | 225 | 226 | 227 | 2008-01-14T07:17:14.000000Z 228 | 555990cd17ea2aa1cd0d0a9eceb2f48f 229 | 2008-01-13T19:07:39.125032Z 230 | 46 231 | cypher 232 | 233 | not.rb 234 | file 235 | 236 | 237 | 238 | 239 | 2008-01-14T07:17:14.000000Z 240 | 1d5844b0fb76be86dcfb9b13a64aad2f 241 | 2008-01-08T23:09:16.531198Z 242 | 38 243 | cypher 244 | 245 | convertable_to_file.rb 246 | file 247 | 248 | 249 | 250 | 251 | 2008-02-22T18:17:58.000000Z 252 | 9666fdefe507aa2958a72aef3a9a5977 253 | 2008-02-22T16:54:56.894766Z 254 | 68 255 | avdi 256 | 257 | with.rb 258 | file 259 | 260 | 261 | 262 | 263 | 2008-01-14T07:17:14.000000Z 264 | 2cb18a61c6af5ec303aab3c212522075 265 | 2008-01-08T23:09:16.531198Z 266 | 38 267 | cypher 268 | 269 | google.rb 270 | file 271 | 272 | 273 | 274 | 275 | 2008-01-14T07:17:14.000000Z 276 | 5d9b1275328196be0a00f2ba414bb9bf 277 | 2008-01-13T19:07:47.366519Z 278 | 50 279 | cypher 280 | 281 | -------------------------------------------------------------------------------- /spec/interactive_editor_spec.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require File.join(File.dirname(__FILE__), "spec_helper") 3 | 4 | require 'spec' 5 | require 'irb' 6 | require 'delegate' 7 | require File.join(File.dirname(__FILE__), '..', 'lib', 'utility_belt', 'interactive_editor') 8 | 9 | # Using SimpleDelegator allows us to replace the constants without triggering a 10 | # "constant redefined" warning. 11 | module StubPlatform 12 | ARCH = SimpleDelegator.new(:x86) 13 | OS = SimpleDelegator.new(:unix) 14 | IMPL = SimpleDelegator.new(:linux) 15 | end 16 | 17 | # Sneak a stub Platform class into InteractiveEditor so that we don't have to 18 | # override constants on the real Platform module 19 | # 20 | # P.S. This ugliness is why libraries should always prefer to expose methods 21 | # over constants. 22 | class InteractiveEditor 23 | Platform = StubPlatform 24 | end 25 | 26 | describe InteractiveEditor, "given no clues as to what editor to use" do 27 | before :each do 28 | ENV.delete("VISUAL") 29 | ENV.delete("EDITOR") 30 | Kernel.stub!(:test).and_return(false) 31 | File.stub!(:executable?).and_return(false) 32 | end 33 | 34 | it "should complain" do 35 | proc do 36 | InteractiveEditor.sensible_editor 37 | end.should raise_error 38 | end 39 | end 40 | 41 | describe InteractiveEditor, 42 | "given a Mac OS X platform and no editor environment vars" do 43 | 44 | before :each do 45 | ENV.delete("VISUAL") 46 | ENV.delete("EDITOR") 47 | @old_impl = StubPlatform::IMPL.__getobj__ 48 | StubPlatform::IMPL.__setobj__(:macosx) 49 | end 50 | 51 | after :each do 52 | StubPlatform::IMPL.__setobj__(@old_impl) 53 | end 54 | 55 | it "should use the OS X 'open' command as the default editor" do 56 | InteractiveEditor.sensible_editor.should == "open" 57 | end 58 | end 59 | 60 | # xdg-open is a facility from the freedesktop.org, available on some recent free 61 | # desktop operating systems (like Ubuntu). It uses the desktop environments 62 | # filetype associations to determine what program to open a file in. 63 | describe InteractiveEditor, 64 | "given a Linux OS and no environment vars" do 65 | 66 | before :each do 67 | ENV.delete("VISUAL") 68 | ENV.delete("EDITOR") 69 | @old_impl = StubPlatform::IMPL.__getobj__ 70 | StubPlatform::OS.__setobj__(:linux) 71 | File.stub!(:executable?).and_return(true) 72 | end 73 | 74 | after :each do 75 | StubPlatform::IMPL.__setobj__(@old_impl) 76 | end 77 | 78 | it "should attempt to use 'xdg-open' command as the default editor" do 79 | File.should_receive(:executable?). 80 | with("/usr/bin/xdg-open"). 81 | and_return(true) 82 | InteractiveEditor.sensible_editor.should == "/usr/bin/xdg-open" 83 | end 84 | end 85 | 86 | # /usr/bin/sensible-editor is a Debian-ism AFAIK 87 | describe InteractiveEditor, 88 | "given the existence of /usr/bin/sensible-editor and no xdg-open" do 89 | it "should use /usr/bin/sensible-editor as the default editor" do 90 | File.should_receive(:executable?). 91 | with("/usr/bin/xdg-open"). 92 | and_return(false) 93 | File.should_receive(:executable?). 94 | with("/usr/bin/sensible-editor"). 95 | and_return(true) 96 | InteractiveEditor.sensible_editor.should == "/usr/bin/sensible-editor" 97 | end 98 | end 99 | 100 | describe InteractiveEditor, "given an EDITOR environment variable" do 101 | before :each do 102 | File.stub!(:executable?).and_return(true) 103 | ENV["EDITOR"] = "MY_EDITOR" 104 | end 105 | 106 | after :each do 107 | ENV.delete("EDITOR") 108 | end 109 | 110 | it "should use the EDITOR environment variable to determine a sensible editor" do 111 | InteractiveEditor.sensible_editor.should == "MY_EDITOR" 112 | end 113 | end 114 | 115 | describe InteractiveEditor, "given a VISUAL environment variable" do 116 | before :each do 117 | File.stub!(:executable?).and_return(true) 118 | ENV["EDITOR"] = "MY_EDITOR" 119 | ENV["VISUAL"] = "MY_VISUAL_EDITOR" 120 | end 121 | 122 | after :each do 123 | ENV.delete("EDITOR") 124 | ENV.delete("VISUAL") 125 | end 126 | 127 | it "should use the environment variable to determine a sensible editor" do 128 | InteractiveEditor.sensible_editor.should == "MY_VISUAL_EDITOR" 129 | end 130 | end 131 | 132 | describe InteractiveEditing, "(calling out to an external editor)" do 133 | before :each do 134 | @it = Object.new 135 | @it.extend(InteractiveEditing) 136 | @editor = stub("Editor", :edit_interactively => nil) 137 | @editor_path = stub("Editor Path") 138 | InteractiveEditor.stub!(:sensible_editor).and_return(@editor_path) 139 | InteractiveEditor.stub!(:new).and_return(@editor) 140 | end 141 | 142 | it "should use InteractiveEditor to determine default editor" do 143 | @it.edit_interactively 144 | IRB.conf[:interactive_editors][@editor_path].should equal(@editor) 145 | end 146 | end 147 | -------------------------------------------------------------------------------- /spec/.svn/text-base/interactive_editor_spec.rb.svn-base: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require File.join(File.dirname(__FILE__), "spec_helper") 3 | 4 | require 'spec' 5 | require 'irb' 6 | require 'delegate' 7 | require File.join(File.dirname(__FILE__), '..', 'lib', 'utility_belt', 'interactive_editor') 8 | 9 | # Using SimpleDelegator allows us to replace the constants without triggering a 10 | # "constant redefined" warning. 11 | module StubPlatform 12 | ARCH = SimpleDelegator.new(:x86) 13 | OS = SimpleDelegator.new(:unix) 14 | IMPL = SimpleDelegator.new(:linux) 15 | end 16 | 17 | # Sneak a stub Platform class into InteractiveEditor so that we don't have to 18 | # override constants on the real Platform module 19 | # 20 | # P.S. This ugliness is why libraries should always prefer to expose methods 21 | # over constants. 22 | class InteractiveEditor 23 | Platform = StubPlatform 24 | end 25 | 26 | describe InteractiveEditor, "given no clues as to what editor to use" do 27 | before :each do 28 | ENV.delete("VISUAL") 29 | ENV.delete("EDITOR") 30 | Kernel.stub!(:test).and_return(false) 31 | File.stub!(:executable?).and_return(false) 32 | end 33 | 34 | it "should complain" do 35 | lambda do 36 | InteractiveEditor.sensible_editor 37 | end.should raise_error 38 | end 39 | end 40 | 41 | describe InteractiveEditor, 42 | "given a Mac OS X platform and no editor environment vars" do 43 | 44 | before :each do 45 | ENV.delete("VISUAL") 46 | ENV.delete("EDITOR") 47 | @old_impl = StubPlatform::IMPL.__getobj__ 48 | StubPlatform::IMPL.__setobj__(:macosx) 49 | end 50 | 51 | after :each do 52 | StubPlatform::IMPL.__setobj__(@old_impl) 53 | end 54 | 55 | it "should use the OS X 'open' command as the default editor" do 56 | InteractiveEditor.sensible_editor.should == "open" 57 | end 58 | end 59 | 60 | # xdg-open is a facility from the freedesktop.org, available on some recent free 61 | # desktop operating systems (like Ubuntu). It uses the desktop environments 62 | # filetype associations to determine what program to open a file in. 63 | describe InteractiveEditor, 64 | "given a Linux OS and no environment vars" do 65 | 66 | before :each do 67 | ENV.delete("VISUAL") 68 | ENV.delete("EDITOR") 69 | @old_impl = StubPlatform::IMPL.__getobj__ 70 | StubPlatform::OS.__setobj__(:linux) 71 | File.stub!(:executable?).and_return(true) 72 | end 73 | 74 | after :each do 75 | StubPlatform::IMPL.__setobj__(@old_impl) 76 | end 77 | 78 | it "should attempt to use 'xdg-open' command as the default editor" do 79 | File.should_receive(:executable?). 80 | with("/usr/bin/xdg-open"). 81 | and_return(true) 82 | InteractiveEditor.sensible_editor.should == "/usr/bin/xdg-open" 83 | end 84 | end 85 | 86 | # /usr/bin/sensible-editor is a Debian-ism AFAIK 87 | describe InteractiveEditor, 88 | "given the existence of /usr/bin/sensible-editor and no xdg-open" do 89 | it "should use /usr/bin/sensible-editor as the default editor" do 90 | File.should_receive(:executable?). 91 | with("/usr/bin/xdg-open"). 92 | and_return(false) 93 | File.should_receive(:executable?). 94 | with("/usr/bin/sensible-editor"). 95 | and_return(true) 96 | InteractiveEditor.sensible_editor.should == "/usr/bin/sensible-editor" 97 | end 98 | end 99 | 100 | describe InteractiveEditor, "given an EDITOR environment variable" do 101 | before :each do 102 | File.stub!(:executable?).and_return(true) 103 | ENV["EDITOR"] = "MY_EDITOR" 104 | end 105 | 106 | after :each do 107 | ENV.delete("EDITOR") 108 | end 109 | 110 | it "should use the EDITOR environment variable to determine a sensible editor" do 111 | InteractiveEditor.sensible_editor.should == "MY_EDITOR" 112 | end 113 | end 114 | 115 | describe InteractiveEditor, "given a VISUAL environment variable" do 116 | before :each do 117 | File.stub!(:executable?).and_return(true) 118 | ENV["EDITOR"] = "MY_EDITOR" 119 | ENV["VISUAL"] = "MY_VISUAL_EDITOR" 120 | end 121 | 122 | after :each do 123 | ENV.delete("EDITOR") 124 | ENV.delete("VISUAL") 125 | end 126 | 127 | it "should use the environment variable to determine a sensible editor" do 128 | InteractiveEditor.sensible_editor.should == "MY_VISUAL_EDITOR" 129 | end 130 | end 131 | 132 | describe InteractiveEditing, "(calling out to an external editor)" do 133 | before :each do 134 | @it = Object.new 135 | @it.extend(InteractiveEditing) 136 | @editor = stub("Editor", :edit_interactively => nil) 137 | @editor_path = stub("Editor Path") 138 | InteractiveEditor.stub!(:sensible_editor).and_return(@editor_path) 139 | InteractiveEditor.stub!(:new).and_return(@editor) 140 | end 141 | 142 | it "should use InteractiveEditor to determine default editor" do 143 | @it.edit_interactively 144 | IRB.conf[:interactive_editors][@editor_path].should equal(@editor) 145 | end 146 | end 147 | -------------------------------------------------------------------------------- /html/authorship.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Utility Belt: Authorship 11 | 12 | 13 | 14 |
15 | 19 | 20 |
21 |

Site menu:

22 | 28 |
29 | 30 |
31 |

Copyright And Authorship

32 |

COMMUNITY EFFORT

33 | 34 |

The majority of this code was written by other people and compiled, nicked, nabbed, herded, gathered, copied, or pilfered by me (Giles Bowkett). Check the links in the copyright notice for more detail. Thanks also to Bob Hutchison, Avdi Grimm, Marcus Derencius, Markus Prinz, Ben Bleything, Reginald Braithwaite-Lee, and Robert Berger for bug fixes, new features, documentation, and bug reports.

35 | 36 |

LICENSE

37 | 38 |
39 | (The MIT License)
40 | 
41 | Copyright (c) 2006-2007 Giles Bowkett
42 | Portions Copyright (c) 2006-2007 Ben Bleything
43 | Portions Copyright (c) 2006-2007 Reginald Braithwaite-Lee
44 | Portions Copyright (c) 2006-2007 Gregory Brown
45 | Portions Copyright (c) 2006-2007 Jamis Buck
46 | Portions Copyright (c) 2006-2007 Mike Clark
47 | Portions Copyright (c) 2006-2007 Jay Fields
48 | Portions Copyright (c) 2005 David Heinemeier Hansson
49 | Portions Copyright (c) 2006-2007 Ara T. Howard
50 | Portions Copyright (c) 2006-2007 Pat Maddox
51 | Portions Copyright (c) 2006-2007 Marcel Molina, Jr.
52 | Portions Copyright (c) 2006-2007 Rick DeNatale
53 | Portions Copyright (c) 2006-2007 Projectionist (Marcel Molina? Chad Fowler?)
54 | Portions Copyright (c) 2006-2007 Dan Yoder
55 | 
56 | Permission is hereby granted, free of charge, to any person obtaining
57 | a copy of this software and associated documentation files (the
58 | 'Software'), to deal in the Software without restriction, including
59 | without limitation the rights to use, copy, modify, merge, publish,
60 | distribute, sublicense, and/or sell copies of the Software, and to
61 | permit persons to whom the Software is furnished to do so, subject to
62 | the following conditions:
63 | 
64 | The above copyright notice and this permission notice shall be
65 | included in all copies or substantial portions of the Software.
66 | 
67 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
68 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
69 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
70 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
71 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
72 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
73 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
74 | 75 |

THE BATMAN GRAPHIC

76 | 77 |

Is that cool or what? I have no idea where I found it. (If you're the creator, a thousand apologies. I just hella dig it.)

78 | 79 |
80 | 81 | 84 |
85 | 86 | 87 | -------------------------------------------------------------------------------- /html/.svn/text-base/authorship.html.svn-base: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Utility Belt: Authorship 11 | 12 | 13 | 14 |
15 | 19 | 20 |
21 |

Site menu:

22 | 28 |
29 | 30 |
31 |

Copyright And Authorship

32 |

COMMUNITY EFFORT

33 | 34 |

The majority of this code was written by other people and compiled, nicked, nabbed, herded, gathered, copied, or pilfered by me (Giles Bowkett). Check the links in the copyright notice for more detail. Thanks also to Bob Hutchison, Avdi Grimm, Marcus Derencius, Markus Prinz, Ben Bleything, Reginald Braithwaite-Lee, and Robert Berger for bug fixes, new features, documentation, and bug reports.

35 | 36 |

LICENSE

37 | 38 |
39 | (The MIT License)
40 | 
41 | Copyright (c) 2006-2007 Giles Bowkett
42 | Portions Copyright (c) 2006-2007 Ben Bleything
43 | Portions Copyright (c) 2006-2007 Reginald Braithwaite-Lee
44 | Portions Copyright (c) 2006-2007 Gregory Brown
45 | Portions Copyright (c) 2006-2007 Jamis Buck
46 | Portions Copyright (c) 2006-2007 Mike Clark
47 | Portions Copyright (c) 2006-2007 Jay Fields
48 | Portions Copyright (c) 2005 David Heinemeier Hansson
49 | Portions Copyright (c) 2006-2007 Ara T. Howard
50 | Portions Copyright (c) 2006-2007 Pat Maddox
51 | Portions Copyright (c) 2006-2007 Marcel Molina, Jr.
52 | Portions Copyright (c) 2006-2007 Rick DeNatale
53 | Portions Copyright (c) 2006-2007 Projectionist (Marcel Molina? Chad Fowler?)
54 | Portions Copyright (c) 2006-2007 Dan Yoder
55 | 
56 | Permission is hereby granted, free of charge, to any person obtaining
57 | a copy of this software and associated documentation files (the
58 | 'Software'), to deal in the Software without restriction, including
59 | without limitation the rights to use, copy, modify, merge, publish,
60 | distribute, sublicense, and/or sell copies of the Software, and to
61 | permit persons to whom the Software is furnished to do so, subject to
62 | the following conditions:
63 | 
64 | The above copyright notice and this permission notice shall be
65 | included in all copies or substantial portions of the Software.
66 | 
67 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
68 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
69 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
70 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
71 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
72 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
73 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
74 | 75 |

THE BATMAN GRAPHIC

76 | 77 |

Is that cool or what? I have no idea where I found it. (If you're the creator, a thousand apologies. I just hella dig it.)

78 | 79 |
80 | 81 | 84 |
85 | 86 | 87 | -------------------------------------------------------------------------------- /html/andreas00.css: -------------------------------------------------------------------------------- 1 | /* andreas00 - an open source xhtml/css website layout by Andreas Viklund - http://andreasviklund.com . Free to use for any purpose as long as the proper credits are given to the original author. 2 | Version: 1.1 (Apr 20, 2006) */ 3 | 4 | /***** Body and main container *****/ 5 | 6 | body { 7 | margin:0 auto; 8 | padding:0; 9 | font:76% Verdana,Tahoma,Arial,sans-serif; 10 | background:#eaeaea url(bg.gif) top center repeat-y; 11 | color:#3a3a3a; 12 | } 13 | 14 | #wrap { 15 | background-color:#ffffff; 16 | color:#303030; 17 | margin:0 auto; 18 | padding:1px 5px; 19 | width:760px; 20 | } 21 | 22 | /***** Header *****/ 23 | 24 | #header { 25 | color:#505050; 26 | background:#ffffff url(http://s3.amazonaws.com/giles/the_tao_of_bondage_vigilantes.jpg) bottom left no-repeat; 27 | height:250px; 28 | margin:0 0 10px 0; 29 | padding:0; 30 | } 31 | 32 | #header h1 { 33 | font-size:2.5em; 34 | font-weight:normal; 35 | letter-spacing:-2px; 36 | margin:0 0 4px 15px; 37 | padding:15px 0 0 0; 38 | } 39 | 40 | #header h1 a,#header h1 a:hover { 41 | padding:0; 42 | } 43 | 44 | #header p { 45 | font-size:1.1em; 46 | letter-spacing:-1px; 47 | margin:0 0 20px 15px; 48 | padding:0 0 0 3px; 49 | } 50 | 51 | /***** Left sidebar *****/ 52 | 53 | #avmenu { 54 | clear:left; 55 | float:left; 56 | width:150px; 57 | margin:0 0 10px 0; 58 | padding:0; 59 | } 60 | 61 | #avmenu ul { 62 | list-style:none; 63 | width:150px; 64 | margin:0 0 20px 0; 65 | padding:0; 66 | } 67 | 68 | #avmenu li { 69 | margin-bottom:5px; 70 | } 71 | 72 | #avmenu li a { 73 | font-weight:bold; 74 | height:20px; 75 | text-decoration:none; 76 | color:#505050; 77 | display:block; 78 | padding:6px 0 0 10px; 79 | background:#f4f4f4 url(menubg.gif) bottom left repeat-x; 80 | border-top:1px solid #d8d8d8; 81 | border-right:1px solid #d8d8d8; 82 | border-bottom:1px solid #d8d8d8; 83 | border-left:4px solid #cccccc; 84 | } 85 | 86 | #avmenu li a:hover, #avmenu li a.current { 87 | background:#eaeaea url(menubg2.gif) bottom left repeat-x; 88 | color:#505050; 89 | border-top:1px solid #b0b0b0; 90 | border-right:1px solid #b0b0b0; 91 | border-bottom:1px solid #b0b0b0; 92 | border-left:4px solid #505050; 93 | } 94 | 95 | #avmenu ul ul { 96 | margin:5px 0 5px 15px; 97 | font-size:0.9em; 98 | width:135px; 99 | } 100 | 101 | #avmenu ul ul a { 102 | height:16px; 103 | margin:0; 104 | padding:4px 0 0 8px; 105 | } 106 | 107 | #avmenu h2 { 108 | font-size:1.5em; 109 | font-weight:normal; 110 | line-height:1.8em; 111 | } 112 | 113 | /***** Right sidebar *****/ 114 | 115 | #extras { 116 | float:right; 117 | width:130px; 118 | margin:0 0 10px 0; 119 | padding:0; 120 | font-size:0.9em; 121 | } 122 | 123 | #extras p, #extras ul { 124 | margin:0 0 1.5em 0; 125 | line-height:1.3em; 126 | padding:0; 127 | } 128 | 129 | #extras a { 130 | font-weight:bold; 131 | } 132 | 133 | #extras li { 134 | list-style:none; 135 | margin:0 0 6px 0; 136 | padding:0; 137 | } 138 | 139 | #extras h2 { 140 | font-size:1.6em; 141 | font-weight:normal; 142 | margin:0 0 6px 0; 143 | ; 144 | letter-spacing:-1px; 145 | } 146 | 147 | /***** Main content *****/ 148 | 149 | #content { 150 | margin:10px 140px 10px 160px; 151 | padding:0; 152 | line-height:1.5em; 153 | text-align:left; 154 | } 155 | 156 | #contentwide { 157 | margin:10px 0 10px 160px; 158 | padding:0; 159 | line-height:1.5em; 160 | text-align:left; 161 | } 162 | 163 | #contentfull { 164 | margin:10px 10px 10px 10px; 165 | padding:2px 0 0 0; 166 | line-height:1.5em; 167 | text-align:left; 168 | } 169 | 170 | #content h2, #contentwide h2, #contentfull h2 { 171 | font-size:1.8em; 172 | font-weight:normal; 173 | margin:8px 0 10px 0px; 174 | padding:0; 175 | padding-left: 10px; 176 | line-height:1.8em; 177 | background-color: #440055; 178 | color: white; 179 | } 180 | 181 | #content h3, #contentwide h3, #contentfull h3 { 182 | line-height:1.8em; 183 | background-color: black; 184 | color: white; 185 | font-size:1.5em; 186 | font-weight:normal; 187 | margin:6px 0 6px 0; 188 | padding:0; 189 | padding-left: 10px; 190 | } 191 | 192 | #content img, #contentwide img, #contentfull img { 193 | padding:1px; 194 | display:inline; 195 | background:#cccccc; 196 | color:#303030; 197 | border:4px solid #f0f0f0; 198 | } 199 | 200 | #content a, #contentwide a, #contentfull a { 201 | } 202 | 203 | #content ul, #content ol, 204 | #contentwide ul, #contentwide ol, 205 | #contentfull ul, #contentfull ol { 206 | margin:0 0 16px 20px; 207 | padding:0; 208 | } 209 | 210 | #content ul ul, #content ol ol, 211 | #contentwide ul ul, #contentwide ol ol, 212 | #contentfull ul ul, #contentfull ol ol { 213 | margin:2px 0 2px 20px; 214 | } 215 | 216 | #content li, #contentwide li, #contentfull li { 217 | margin:0 0 2px 10px; 218 | padding:0 0 0 4px; 219 | } 220 | 221 | /***** Footer *****/ 222 | 223 | #footer { 224 | clear:both; 225 | margin:0 auto; 226 | padding:8px 0; 227 | border-top:2px solid #dadada; 228 | width:760px; 229 | text-align:center; 230 | color:#808080; 231 | background-color:#ffffff; 232 | font-size:0.9em; 233 | } 234 | 235 | #footer p { 236 | padding:0; 237 | margin:0; 238 | } 239 | 240 | #footer a { 241 | color:#808080; 242 | background-color:inherit; 243 | text-decoration:none; 244 | } 245 | 246 | #footer a:hover { 247 | text-decoration:underline; 248 | } 249 | 250 | /***** Various tags *****/ 251 | 252 | a { 253 | text-decoration:none; 254 | color:#505050; 255 | background-color:inherit; 256 | } 257 | 258 | a:hover { 259 | text-decoration:underline; 260 | color:#286ea0; 261 | background-color:inherit; 262 | } 263 | 264 | a img { 265 | border:0; 266 | } 267 | 268 | p { 269 | margin:0 0 16px 0; 270 | } 271 | 272 | blockquote { 273 | border-top:1px solid #d8d8d8; 274 | border-right:1px solid #d8d8d8; 275 | border-bottom:1px solid #d8d8d8; 276 | border-left:4px solid #cccccc; 277 | margin:16px; 278 | padding:7px 7px 7px 11px; 279 | background:#f4f4f4 url(menubg.gif) bottom left repeat-x; 280 | color:#505050; 281 | } 282 | 283 | blockquote p { 284 | font-size:1.1em; 285 | line-height:1.3em; 286 | margin:0; 287 | } 288 | 289 | /***** Table styles *****/ 290 | 291 | table { 292 | margin:0 0 16px 0; 293 | padding:0; 294 | line-height:1.3em; 295 | border-collapse:collapse; 296 | border:1px solid #d8d8d8; 297 | } 298 | 299 | caption { 300 | text-align:left; 301 | font-size:1.5em; 302 | font-weight:normal; 303 | margin:0; 304 | padding:6px 0 8px 0; 305 | } 306 | 307 | th { 308 | padding:7px; 309 | text-align:left; 310 | background:#eaeaea url(menubg2.gif) bottom left repeat-x; 311 | color:#505050; 312 | } 313 | 314 | td { 315 | padding:7px; 316 | font-size:0.9em; 317 | text-align:left; 318 | background:#f4f4f4 url(menubg.gif) bottom left repeat-x; 319 | color:#303030; 320 | } 321 | 322 | /***** Form styles *****/ 323 | 324 | .button { 325 | border-top:1px solid #d8d8d8; 326 | border-right:1px solid #d8d8d8; 327 | border-bottom:1px solid #d8d8d8; 328 | border-left:4px solid #cccccc; 329 | margin:0 0 15px 0; 330 | padding:7px 7px 7px 11px; 331 | background:#f4f4f4 url(menubg.gif) bottom left repeat-x; 332 | color:#505050; 333 | font-weight:bold; 334 | width:120px; 335 | } 336 | 337 | input, textarea { 338 | border:1px solid #cccccc; 339 | font-family:Verdana,Tahoma,Arial,Sans-Serif; 340 | font-size:1em; 341 | margin:0; 342 | padding:4px; 343 | } 344 | 345 | label { 346 | margin:2px; 347 | } 348 | 349 | input { 350 | width:200px; 351 | } 352 | 353 | textarea { 354 | width:400px; 355 | } 356 | 357 | /***** Search box *****/ 358 | 359 | #searchbox { 360 | padding:0; 361 | margin:6px 0 16px 0; 362 | } 363 | 364 | #searchform { 365 | background:#ffffff; 366 | border:1px solid #cccccc; 367 | color:#505050; 368 | font-size:0.9em; 369 | padding:4px; 370 | width:116px; 371 | } 372 | 373 | #searchbox label { 374 | display:none; 375 | } 376 | 377 | /***** Various classes *****/ 378 | 379 | .left { 380 | margin:10px 10px 5px 0; 381 | float:left; 382 | } 383 | 384 | .right { 385 | margin:10px 0 5px 10px; 386 | float:right; 387 | } 388 | 389 | .announce { 390 | margin:10px 0 10px 0; 391 | padding:10px 10px 5px 10px; 392 | width:105px; 393 | color:#505050; 394 | background:#f4f4f4 url(menubg.gif) bottom left repeat-x; 395 | border-top:1px solid #d8d8d8; 396 | border-right:1px solid #d8d8d8; 397 | border-bottom:1px solid #d8d8d8; 398 | border-left:4px solid #cccccc; 399 | line-height:1.3em; 400 | } 401 | 402 | .announce a { 403 | font-weight:bold; 404 | } 405 | 406 | .announce p { 407 | font-size:0.9em; 408 | } 409 | 410 | .announce h2 { 411 | margin:0 0 10px 0; 412 | padding:0; 413 | } 414 | 415 | #avmenu .announce { 416 | width:125px; 417 | } 418 | 419 | .textright { 420 | text-align:right; 421 | margin:-10px 0 4px 0; 422 | } 423 | 424 | .center { 425 | text-align:center; 426 | } 427 | 428 | .small { 429 | font-size:0.8em; 430 | } 431 | 432 | .large { 433 | font-size:1.3em; 434 | } 435 | 436 | .bold { 437 | font-weight:bold; 438 | } 439 | 440 | .highlighted { 441 | padding:3px; 442 | background-color:#f0f0f0; 443 | color:#303030; 444 | border:1px solid #b0b0b0; 445 | } 446 | 447 | .hide { 448 | display:none; 449 | } -------------------------------------------------------------------------------- /html/.svn/text-base/andreas00.css.svn-base: -------------------------------------------------------------------------------- 1 | /* andreas00 - an open source xhtml/css website layout by Andreas Viklund - http://andreasviklund.com . Free to use for any purpose as long as the proper credits are given to the original author. 2 | Version: 1.1 (Apr 20, 2006) */ 3 | 4 | /***** Body and main container *****/ 5 | 6 | body { 7 | margin:0 auto; 8 | padding:0; 9 | font:76% Verdana,Tahoma,Arial,sans-serif; 10 | background:#eaeaea url(bg.gif) top center repeat-y; 11 | color:#3a3a3a; 12 | } 13 | 14 | #wrap { 15 | background-color:#ffffff; 16 | color:#303030; 17 | margin:0 auto; 18 | padding:1px 5px; 19 | width:760px; 20 | } 21 | 22 | /***** Header *****/ 23 | 24 | #header { 25 | color:#505050; 26 | background:#ffffff url(http://s3.amazonaws.com/giles/the_tao_of_bondage_vigilantes.jpg) bottom left no-repeat; 27 | height:250px; 28 | margin:0 0 10px 0; 29 | padding:0; 30 | } 31 | 32 | #header h1 { 33 | font-size:2.5em; 34 | font-weight:normal; 35 | letter-spacing:-2px; 36 | margin:0 0 4px 15px; 37 | padding:15px 0 0 0; 38 | } 39 | 40 | #header h1 a,#header h1 a:hover { 41 | padding:0; 42 | } 43 | 44 | #header p { 45 | font-size:1.1em; 46 | letter-spacing:-1px; 47 | margin:0 0 20px 15px; 48 | padding:0 0 0 3px; 49 | } 50 | 51 | /***** Left sidebar *****/ 52 | 53 | #avmenu { 54 | clear:left; 55 | float:left; 56 | width:150px; 57 | margin:0 0 10px 0; 58 | padding:0; 59 | } 60 | 61 | #avmenu ul { 62 | list-style:none; 63 | width:150px; 64 | margin:0 0 20px 0; 65 | padding:0; 66 | } 67 | 68 | #avmenu li { 69 | margin-bottom:5px; 70 | } 71 | 72 | #avmenu li a { 73 | font-weight:bold; 74 | height:20px; 75 | text-decoration:none; 76 | color:#505050; 77 | display:block; 78 | padding:6px 0 0 10px; 79 | background:#f4f4f4 url(menubg.gif) bottom left repeat-x; 80 | border-top:1px solid #d8d8d8; 81 | border-right:1px solid #d8d8d8; 82 | border-bottom:1px solid #d8d8d8; 83 | border-left:4px solid #cccccc; 84 | } 85 | 86 | #avmenu li a:hover, #avmenu li a.current { 87 | background:#eaeaea url(menubg2.gif) bottom left repeat-x; 88 | color:#505050; 89 | border-top:1px solid #b0b0b0; 90 | border-right:1px solid #b0b0b0; 91 | border-bottom:1px solid #b0b0b0; 92 | border-left:4px solid #505050; 93 | } 94 | 95 | #avmenu ul ul { 96 | margin:5px 0 5px 15px; 97 | font-size:0.9em; 98 | width:135px; 99 | } 100 | 101 | #avmenu ul ul a { 102 | height:16px; 103 | margin:0; 104 | padding:4px 0 0 8px; 105 | } 106 | 107 | #avmenu h2 { 108 | font-size:1.5em; 109 | font-weight:normal; 110 | line-height:1.8em; 111 | } 112 | 113 | /***** Right sidebar *****/ 114 | 115 | #extras { 116 | float:right; 117 | width:130px; 118 | margin:0 0 10px 0; 119 | padding:0; 120 | font-size:0.9em; 121 | } 122 | 123 | #extras p, #extras ul { 124 | margin:0 0 1.5em 0; 125 | line-height:1.3em; 126 | padding:0; 127 | } 128 | 129 | #extras a { 130 | font-weight:bold; 131 | } 132 | 133 | #extras li { 134 | list-style:none; 135 | margin:0 0 6px 0; 136 | padding:0; 137 | } 138 | 139 | #extras h2 { 140 | font-size:1.6em; 141 | font-weight:normal; 142 | margin:0 0 6px 0; 143 | ; 144 | letter-spacing:-1px; 145 | } 146 | 147 | /***** Main content *****/ 148 | 149 | #content { 150 | margin:10px 140px 10px 160px; 151 | padding:0; 152 | line-height:1.5em; 153 | text-align:left; 154 | } 155 | 156 | #contentwide { 157 | margin:10px 0 10px 160px; 158 | padding:0; 159 | line-height:1.5em; 160 | text-align:left; 161 | } 162 | 163 | #contentfull { 164 | margin:10px 10px 10px 10px; 165 | padding:2px 0 0 0; 166 | line-height:1.5em; 167 | text-align:left; 168 | } 169 | 170 | #content h2, #contentwide h2, #contentfull h2 { 171 | font-size:1.8em; 172 | font-weight:normal; 173 | margin:8px 0 10px 0px; 174 | padding:0; 175 | padding-left: 10px; 176 | line-height:1.8em; 177 | background-color: #440055; 178 | color: white; 179 | } 180 | 181 | #content h3, #contentwide h3, #contentfull h3 { 182 | line-height:1.8em; 183 | background-color: black; 184 | color: white; 185 | font-size:1.5em; 186 | font-weight:normal; 187 | margin:6px 0 6px 0; 188 | padding:0; 189 | padding-left: 10px; 190 | } 191 | 192 | #content img, #contentwide img, #contentfull img { 193 | padding:1px; 194 | display:inline; 195 | background:#cccccc; 196 | color:#303030; 197 | border:4px solid #f0f0f0; 198 | } 199 | 200 | #content a, #contentwide a, #contentfull a { 201 | } 202 | 203 | #content ul, #content ol, 204 | #contentwide ul, #contentwide ol, 205 | #contentfull ul, #contentfull ol { 206 | margin:0 0 16px 20px; 207 | padding:0; 208 | } 209 | 210 | #content ul ul, #content ol ol, 211 | #contentwide ul ul, #contentwide ol ol, 212 | #contentfull ul ul, #contentfull ol ol { 213 | margin:2px 0 2px 20px; 214 | } 215 | 216 | #content li, #contentwide li, #contentfull li { 217 | margin:0 0 2px 10px; 218 | padding:0 0 0 4px; 219 | } 220 | 221 | /***** Footer *****/ 222 | 223 | #footer { 224 | clear:both; 225 | margin:0 auto; 226 | padding:8px 0; 227 | border-top:2px solid #dadada; 228 | width:760px; 229 | text-align:center; 230 | color:#808080; 231 | background-color:#ffffff; 232 | font-size:0.9em; 233 | } 234 | 235 | #footer p { 236 | padding:0; 237 | margin:0; 238 | } 239 | 240 | #footer a { 241 | color:#808080; 242 | background-color:inherit; 243 | text-decoration:none; 244 | } 245 | 246 | #footer a:hover { 247 | text-decoration:underline; 248 | } 249 | 250 | /***** Various tags *****/ 251 | 252 | a { 253 | text-decoration:none; 254 | color:#505050; 255 | background-color:inherit; 256 | } 257 | 258 | a:hover { 259 | text-decoration:underline; 260 | color:#286ea0; 261 | background-color:inherit; 262 | } 263 | 264 | a img { 265 | border:0; 266 | } 267 | 268 | p { 269 | margin:0 0 16px 0; 270 | } 271 | 272 | blockquote { 273 | border-top:1px solid #d8d8d8; 274 | border-right:1px solid #d8d8d8; 275 | border-bottom:1px solid #d8d8d8; 276 | border-left:4px solid #cccccc; 277 | margin:16px; 278 | padding:7px 7px 7px 11px; 279 | background:#f4f4f4 url(menubg.gif) bottom left repeat-x; 280 | color:#505050; 281 | } 282 | 283 | blockquote p { 284 | font-size:1.1em; 285 | line-height:1.3em; 286 | margin:0; 287 | } 288 | 289 | /***** Table styles *****/ 290 | 291 | table { 292 | margin:0 0 16px 0; 293 | padding:0; 294 | line-height:1.3em; 295 | border-collapse:collapse; 296 | border:1px solid #d8d8d8; 297 | } 298 | 299 | caption { 300 | text-align:left; 301 | font-size:1.5em; 302 | font-weight:normal; 303 | margin:0; 304 | padding:6px 0 8px 0; 305 | } 306 | 307 | th { 308 | padding:7px; 309 | text-align:left; 310 | background:#eaeaea url(menubg2.gif) bottom left repeat-x; 311 | color:#505050; 312 | } 313 | 314 | td { 315 | padding:7px; 316 | font-size:0.9em; 317 | text-align:left; 318 | background:#f4f4f4 url(menubg.gif) bottom left repeat-x; 319 | color:#303030; 320 | } 321 | 322 | /***** Form styles *****/ 323 | 324 | .button { 325 | border-top:1px solid #d8d8d8; 326 | border-right:1px solid #d8d8d8; 327 | border-bottom:1px solid #d8d8d8; 328 | border-left:4px solid #cccccc; 329 | margin:0 0 15px 0; 330 | padding:7px 7px 7px 11px; 331 | background:#f4f4f4 url(menubg.gif) bottom left repeat-x; 332 | color:#505050; 333 | font-weight:bold; 334 | width:120px; 335 | } 336 | 337 | input, textarea { 338 | border:1px solid #cccccc; 339 | font-family:Verdana,Tahoma,Arial,Sans-Serif; 340 | font-size:1em; 341 | margin:0; 342 | padding:4px; 343 | } 344 | 345 | label { 346 | margin:2px; 347 | } 348 | 349 | input { 350 | width:200px; 351 | } 352 | 353 | textarea { 354 | width:400px; 355 | } 356 | 357 | /***** Search box *****/ 358 | 359 | #searchbox { 360 | padding:0; 361 | margin:6px 0 16px 0; 362 | } 363 | 364 | #searchform { 365 | background:#ffffff; 366 | border:1px solid #cccccc; 367 | color:#505050; 368 | font-size:0.9em; 369 | padding:4px; 370 | width:116px; 371 | } 372 | 373 | #searchbox label { 374 | display:none; 375 | } 376 | 377 | /***** Various classes *****/ 378 | 379 | .left { 380 | margin:10px 10px 5px 0; 381 | float:left; 382 | } 383 | 384 | .right { 385 | margin:10px 0 5px 10px; 386 | float:right; 387 | } 388 | 389 | .announce { 390 | margin:10px 0 10px 0; 391 | padding:10px 10px 5px 10px; 392 | width:105px; 393 | color:#505050; 394 | background:#f4f4f4 url(menubg.gif) bottom left repeat-x; 395 | border-top:1px solid #d8d8d8; 396 | border-right:1px solid #d8d8d8; 397 | border-bottom:1px solid #d8d8d8; 398 | border-left:4px solid #cccccc; 399 | line-height:1.3em; 400 | } 401 | 402 | .announce a { 403 | font-weight:bold; 404 | } 405 | 406 | .announce p { 407 | font-size:0.9em; 408 | } 409 | 410 | .announce h2 { 411 | margin:0 0 10px 0; 412 | padding:0; 413 | } 414 | 415 | #avmenu .announce { 416 | width:125px; 417 | } 418 | 419 | .textright { 420 | text-align:right; 421 | margin:-10px 0 4px 0; 422 | } 423 | 424 | .center { 425 | text-align:center; 426 | } 427 | 428 | .small { 429 | font-size:0.8em; 430 | } 431 | 432 | .large { 433 | font-size:1.3em; 434 | } 435 | 436 | .bold { 437 | font-weight:bold; 438 | } 439 | 440 | .highlighted { 441 | padding:3px; 442 | background-color:#f0f0f0; 443 | color:#303030; 444 | border:1px solid #b0b0b0; 445 | } 446 | 447 | .hide { 448 | display:none; 449 | } -------------------------------------------------------------------------------- /html/usage.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Utility Belt: Usage 11 | 12 | 13 | 14 |
15 | 19 | 20 |
21 |

Site menu:

22 | 28 | 29 |
30 | 31 |
32 |

Synopsis And Usage

33 | 34 | 35 |

SYNOPSIS

36 | 37 |

Utility Belt gives you a ton of new options and techniques in IRB. (You may find yourself putting its language patches in actual projects as well.) The way to use Utility Belt is to edit, or create, your .irbrc file. This is analogous to a Unix .bashrc, .tcshrc, .profile, or similar file.

38 | 39 |

Windows users have a couple options. The easiest is to define an environment variable called IRBRC and set it to the full path of your irbrc (e.g. "C:\Documents and Settings\\_irbrc"). Presto, .irbrc for Windows. You could also set your HOME-Variable to any directory you want and put your ".irbrc" in there. (It needs to be called ".irbrc", "_irbrc" won't work). Since Windows Explorer won't let you create a file with a dot in the beginning, use any text editor (Notepad will do just fine) and "Save As" to save it as ".irbrc". (The quotation marks make the magic happen.) We don't recommend this if you're also using MSYS or Cygwin, as they use the same variable for their own purposes.

40 | 41 |

Adding Utility Belt to your .irbrc is easy:

42 | 43 |
require 'rubygems'
 44 | require 'utility_belt'
45 | 46 |

To use the Amazon shortcuts, you also need to set some environment variables. See the section on S3 under "Usage" for more. Also, if your terminal has a light background, you'll need to enable the light-background syntax coloring theme - see the section on themes under "Usage" for more.

47 | 48 |

USAGE

49 | 50 |

Using each of Utility Belt's tools is different:

51 | 52 |

Interactively edit IRB code in your preferred text editor

53 | 54 |

If your preferred text editor is vi(m), emacs, or TextMate, there are built-in commands: vi, emacs, and mate, respectively. To use another editor, use this command:

55 | 56 |
edit_interactively(:the_name_of_my_editor)
57 | 58 |

or

59 | 60 |
edit_interactively("the name of my editor")
61 | 62 |

or

63 | 64 |
edit_interactively("/the/path/to/my/editor")
65 | 66 |

If you're wondering why the method name is so ridiculously long, there's a story there.

67 | 68 |

Read from and write to OS X or Windows clipboard

69 | 70 |

To read:

71 | 72 |
Clipboard.read
73 | 74 |

To write:

75 | 76 |
Clipboard.write("something")
77 | 78 |

Post your code to Pastie with one command (OS X and Windows only)

79 | 80 |

You must first equip the UtilityBelt with pastie in your .irbrc:

81 | 82 |
UtilityBelt.equip(:pastie)
83 | 84 |

This line will also automatically equip the Clipboard, which is required to use pastie.

85 | 86 |

First copy some code into your clipboard, or put it there with the Clipboard.write() class method. Then use the command:

87 | 88 |
pastie
89 | 90 |

or the shortcut version:

91 | 92 |
pst
93 | 94 |

Note that this method currently auto-formats all code as Ruby. Support for other languages is possible but not implemented yet. Also, this code is OS X and Windows only because it uses the Clipboard. (A platform-agnostic version without the clipboard aspect is certainly possible.)

95 | 96 |

Unix-style history buffer

97 | 98 |

Use "h" or "history" to view your command history, and "h! 123" to re-invoke command #123 in your buffer. "h!" with no args will run the last command.

99 | 100 |

Write command history to file or vi

101 | 102 |

To write your history to a file, use "history_write('/path/to/file')". To edit your history in vi, use "history_to_vi" or its shortcut alias "hvi".

103 | 104 |

Grep classes and methods for strings

105 | 106 |

Classes:

107 | 108 |
>> grep_classes("ixnum")
109 | #=> ["Fixnum"]
110 | 
111 | >> grep_classes("num")
112 | #=> ["Bignum", "Fixnum", "Numeric", "REXML::SyncEnumerator"]
113 | 114 |

Methods:

115 | 116 |
>> "any arbitrary string".grep_methods("pretty")
117 | #=> ["pretty_inspect", "pretty_print_instance_variables",
118 | "pretty_print_inspect", "pretty_print", "pretty_print_cycle"]
119 | 
120 | >> 32.grep_methods("*")
121 | #=> ["*", "**"]
122 | 123 |

At some point it'll probably be a good idea to add regex support for these methods. (Of course if I do that, I'll probably have to change the name from grep to ack.)

124 | 125 |

Verbosity controls for regular IRB and Rails console

126 | 127 |

regular IRB: "verbose" or "v" / "quiet" or "q"

128 | 129 |

Rails: "log" method turns verbosity on, there isn't actually any method for turning it off. (Might add one at some point.)

130 | 131 |

Finder shortcuts for Rails console

132 | 133 |
user(:all) / user(1)
134 | 135 |

instead of

136 | 137 |
User.find(:all) / User.find(1)
138 | 139 |

Supports arbitrarily complex finds.

140 | 141 |

Upload shortcut for Amazon S3

142 | 143 |

First, define your secret keys in your environment variables:

144 | 145 |
export AMAZON_ACCESS_KEY_ID='foofoofoofoofoo'
146 | export AMAZON_SECRET_ACCESS_KEY='barbarbarbarbar'
147 | 148 |

(Obviously, replace those with actual values.)

149 | 150 |

Then, you can use

151 | 152 |
aws_upload("bucket_name","filename")
153 | 154 |

To easily upload public-access files. This method will automatically connect to Amazon S3 for you, if your keys are defined in your environment variables. It also writes the resulting Amazon URL to your clipboard, if you're on OS X, so you can easily share the file with others. Note that you have to create the initial buckets manually - see amazon.rubyforge.org for details on that.

155 | 156 |

A good way to use this is actually to have a default bucket, and create a further method in your .irbrc file:

157 | 158 |
def my_bucket_name(filename)
159 |   aws_upload("my_default_bucket",filename)
160 | end
161 | 162 |

Command-line Amazon S3 upload script

163 | 164 |

Utility Belt also includes amazon, a simple command-line uploader for S3. It requires that you set your Amazon environment variables (see above). The usage is:

165 | 166 |
amazon -b my_bucket_name filename other_filename
167 | 168 |

(For any arbitrary number of filenames.)

169 | 170 |

Anytime you want to upload a file to your default bucket on S3, for example, the "images" bucket for your blog - or the "mp3" bucket if you're running a blog like Projectionist - all you have to do is

171 | 172 |
amazon -b blog_files some_file.name
173 | 174 |

Or

175 | 176 |
amazon --bucket blog_files some_file.name
177 | 178 |

And you're good to go. Of course, if that were too many characters to type, you could always take it one step further with a shell script. For instance, in bash:

179 | 180 |
alias b1="amazon --bucket my_main_bucket $1"
181 | alias b2="amazon --bucket my_other_bucket $1"
182 | 183 |

And then you would only have to type:

184 | 185 |
b1 file.name
186 | 187 |

And of course tab completion will handle all the typing of the file name, assuming you choose your file names deliberately ahead of time to make tab completion effective, in which case all you have to type is "b1 f[tab]" and bam.

188 | 189 |

Command-line Google shortcut (OS X only)

190 | 191 |

To pop open a new window in your default browser with Google search results for a given search term, do:

192 | 193 |
google "any given term"
194 | 195 |

For one-word terms, you can omit the quotes:

196 | 197 |
google term
198 | 199 |

If you already have the search term in your clipboard, you can just type:

200 | 201 |
google
202 | 203 |

(The last approach is useful for unusual command-line error messages.)

204 | 205 |

Auto-indentation

206 | 207 |

Just type as normally. This just enables built-in but underused functionality in IRB. (The IRB default auto-indentation isn't perfect, but it clobbers the living hell out of no indentation at all.)

208 | 209 |

_ special variable (like Unix shell var !!)

210 | 211 |

More activation of built-in but underused functionality in IRB. _ functions like !! in Unix, with one subtle difference. Instead of re-issuing the previous command in your history, it gives you the last result of evaluating a command. This means when you start a new IRB session, _ won't go to your history, it'll just give you nil, and it means that some commands can't be repeated exactly. Nine out of ten times, however, it's pretty much the same thing.

212 | 213 |

Note that when combined with the h! in the command history code, you basically have two synonyms for !! here. Neither one is an exact replica, but between the two of them, you should have what you need.

214 | 215 |

Extremely basic themes for Wirble syntax coloring

216 | 217 |

Utility Belt incorporates Wirble as a dependency. Wirble provides syntax coloring. Utility Belt allows you to choose between two syntax coloring themes: Wirble's default, and an alternate color set for terminals with light backgrounds. The default theme is enabled by default (duh), but if you have a terminal with a light background, you can enable the light-background theme just by putting the following line of code in your .irbrc:

218 | 219 |
UtilityBelt::Themes.background(:light)
220 | 221 |

To revert back to the default, just use this:

222 | 223 |
UtilityBelt::Themes.background(:dark)
224 | 225 |

To specify an entirely new syntax color scheme, see the source code for this gem or for Wirble.

226 | 227 |

Pascal/JavaScript-style "with" statement

228 | 229 |

I use this with RSpec's spec_helper. Instead of:

230 | 231 |
Spec::Runner.configure do |config|
232 |   config.use_transactional_fixtures = true
233 |   config.use_instantiated_fixtures  = false
234 |   config.fixture_path = RAILS_ROOT + '/spec/fixtures'
235 |   config.mock_with :flexmock
236 | end
237 | 238 |

I do this:

239 | 240 |
Spec::Runner.configure do |config|
241 |   with(config) do
242 |     use_transactional_fixtures = true
243 |     use_instantiated_fixtures  = false
244 |     fixture_path = RAILS_ROOT + '/spec/fixtures'
245 |     mock_with :flexmock
246 |   end
247 | end
248 | 249 |

Note however that this blew up once and I have no idea why. Caveat emptor, et cetera.

250 | 251 |

String#to_proc

252 | 253 |

Syntactic sugar for functional programming. (More detail here.) Rails' Symbol#to_proc is also included.

254 | 255 |
(1..3).map(&'*2') => [2, 4, 6]
256 | (1..3).map(&'[-1, _, 0]') => [[-1, 1, 0], [-1, 2, 0], [-1, 3, 0]]
257 | (1..3).map(&'x -> y -> x * y').map(&'[2]') => [2, 4, 6]
258 | (1..5).select(&'>2') => [3, 4, 5]
259 | (1..3).map(&'x -> y -> x * y').map(&'.call(2)') => [2, 4, 6]
260 | [5].map(&"(1.._).inject(&'*')") => [120]
261 | 262 |

Add and subtract Hashes with + and -

263 | 264 |
{:a => :b} + {:c => :d} = {:a => :b, :c => :d}
265 | {:a => :b, :c => :d} - {:c => :d} = {:a => :b}
266 | {:a => :b, :c => :d} - :c = {:a => :b}
267 | 268 |

You could already do this with Arrays; now you can do it with Hashes as well. (I was kinda surprised the first time I tried to do this and realized I'd have to write it myself.)

269 | 270 | 271 |

Grammatically-correct is_an? method - no more "is_a? Array" statements

272 | 273 |
>> [].is_an? Array
274 | #=> true
275 | 276 |

Most people don't care, but personally, "is_a? Array" drives me completely insane.

277 | 278 |

Object#not

279 | 280 |

Replace this:

281 | 282 |
if !response.incomplete? && !response.invalid? && response.total > 0
283 | 284 |

With this:

285 | 286 |
if response.not.incomplete? && response.not.invalid? && response.total > 0
287 | 288 |

Syntactic sugar for boolean conditions. (More detail here.)

289 | 290 |

One-character exit command

291 | 292 |
x
293 | 294 |

Because life is too short to type whole words.

295 | 296 | 297 |
298 | 299 | 302 |
303 | 304 | 305 | -------------------------------------------------------------------------------- /html/.svn/text-base/usage.html.svn-base: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Utility Belt: Usage 11 | 12 | 13 | 14 |
15 | 19 | 20 |
21 |

Site menu:

22 | 28 | 29 |
30 | 31 |
32 |

Synopsis And Usage

33 | 34 | 35 |

SYNOPSIS

36 | 37 |

Utility Belt gives you a ton of new options and techniques in IRB. (You may find yourself putting its language patches in actual projects as well.) The way to use Utility Belt is to edit, or create, your .irbrc file. This is analogous to a Unix .bashrc, .tcshrc, .profile, or similar file.

38 | 39 |

Windows users have a couple options. The easiest is to define an environment variable called IRBRC and set it to the full path of your irbrc (e.g. "C:\Documents and Settings\\_irbrc"). Presto, .irbrc for Windows. You could also set your HOME-Variable to any directory you want and put your ".irbrc" in there. (It needs to be called ".irbrc", "_irbrc" won't work). Since Windows Explorer won't let you create a file with a dot in the beginning, use any text editor (Notepad will do just fine) and "Save As" to save it as ".irbrc". (The quotation marks make the magic happen.) We don't recommend this if you're also using MSYS or Cygwin, as they use the same variable for their own purposes.

40 | 41 |

Adding Utility Belt to your .irbrc is easy:

42 | 43 |
require 'rubygems'
 44 | require 'utility_belt'
45 | 46 |

To use the Amazon shortcuts, you also need to set some environment variables. See the section on S3 under "Usage" for more. Also, if your terminal has a light background, you'll need to enable the light-background syntax coloring theme - see the section on themes under "Usage" for more.

47 | 48 |

USAGE

49 | 50 |

Using each of Utility Belt's tools is different:

51 | 52 |

Interactively edit IRB code in your preferred text editor

53 | 54 |

If your preferred text editor is vi(m), emacs, or TextMate, there are built-in commands: vi, emacs, and mate, respectively. To use another editor, use this command:

55 | 56 |
edit_interactively(:the_name_of_my_editor)
57 | 58 |

or

59 | 60 |
edit_interactively("the name of my editor")
61 | 62 |

or

63 | 64 |
edit_interactively("/the/path/to/my/editor")
65 | 66 |

If you're wondering why the method name is so ridiculously long, there's a story there.

67 | 68 |

Read from and write to OS X clipboard

69 | 70 |

To read:

71 | 72 |
MacClipboard.read
73 | 74 |

To write:

75 | 76 |
MacClipboard.write("something")
77 | 78 |

Post your code to Pastie with one command (OS X only)

79 | 80 |

First copy some code into your clipboard, or put it there with the MacClipboard.write() class method. Then use the command:

81 | 82 |
pastie
83 | 84 |

or the shortcut version:

85 | 86 |
pst
87 | 88 |

Note that this method currently auto-formats all code as Ruby. Support for other languages is possible but not implemented yet. Also, this code is OS X only because it uses the MacClipboard. (A platform-agnostic version without the clipboard aspect is certainly possible.)

89 | 90 |

Unix-style history buffer

91 | 92 |

Use "h" or "history" to view your command history, and "h! 123" to re-invoke command #123 in your buffer. "h!" with no args will run the last command.

93 | 94 |

Write command history to file or vi

95 | 96 |

To write your history to a file, use "history_write('/path/to/file')". To edit your history in vi, use "history_to_vi" or its shortcut alias "hvi".

97 | 98 |

Grep classes and methods for strings

99 | 100 |

Classes:

101 | 102 |
>> grep_classes("ixnum")
103 | #=> ["Fixnum"]
104 | 
105 | >> grep_classes("num")
106 | #=> ["Bignum", "Fixnum", "Numeric", "REXML::SyncEnumerator"]
107 | 108 |

Methods:

109 | 110 |
>> "any arbitrary string".grep_methods("pretty")
111 | #=> ["pretty_inspect", "pretty_print_instance_variables",
112 | "pretty_print_inspect", "pretty_print", "pretty_print_cycle"]
113 | 
114 | >> 32.grep_methods("*")
115 | #=> ["*", "**"]
116 | 117 |

At some point it'll probably be a good idea to add regex support for these methods. (Of course if I do that, I'll probably have to change the name from grep to ack.)

118 | 119 |

Verbosity controls for regular IRB and Rails console

120 | 121 |

regular IRB: "verbose" or "v" / "quiet" or "q"

122 | 123 |

Rails: "log" method turns verbosity on, there isn't actually any method for turning it off. (Might add one at some point.)

124 | 125 |

Finder shortcuts for Rails console

126 | 127 |
user(:all) / user(1)
128 | 129 |

instead of

130 | 131 |
User.find(:all) / User.find(1)
132 | 133 |

Supports arbitrarily complex finds.

134 | 135 |

Upload shortcut for Amazon S3

136 | 137 |

First, define your secret keys in your environment variables:

138 | 139 |
export AMAZON_ACCESS_KEY_ID='foofoofoofoofoo'
140 | export AMAZON_SECRET_ACCESS_KEY='barbarbarbarbar'
141 | 142 |

(Obviously, replace those with actual values.)

143 | 144 |

Then, you can use

145 | 146 |
aws_upload("bucket_name","filename")
147 | 148 |

To easily upload public-access files. This method will automatically connect to Amazon S3 for you, if your keys are defined in your environment variables. It also writes the resulting Amazon URL to your clipboard, if you're on OS X, so you can easily share the file with others. Note that you have to create the initial buckets manually - see amazon.rubyforge.org for details on that.

149 | 150 |

A good way to use this is actually to have a default bucket, and create a further method in your .irbrc file:

151 | 152 |
def my_bucket_name(filename)
153 |   aws_upload("my_default_bucket",filename)
154 | end
155 | 156 |

Command-line Amazon S3 upload script

157 | 158 |

Utility Belt also includes amazon, a simple command-line uploader for S3. It requires that you set your Amazon environment variables (see above). The usage is:

159 | 160 |
amazon -b my_bucket_name filename other_filename
161 | 162 |

(For any arbitrary number of filenames.)

163 | 164 |

Anytime you want to upload a file to your default bucket on S3, for example, the "images" bucket for your blog - or the "mp3" bucket if you're running a blog like Projectionist - all you have to do is

165 | 166 |
amazon -b blog_files some_file.name
167 | 168 |

Or

169 | 170 |
amazon --bucket blog_files some_file.name
171 | 172 |

And you're good to go. Of course, if that were too many characters to type, you could always take it one step further with a shell script. For instance, in bash:

173 | 174 |
alias b1="amazon --bucket my_main_bucket $1"
175 | alias b2="amazon --bucket my_other_bucket $1"
176 | 177 |

And then you would only have to type:

178 | 179 |
b1 file.name
180 | 181 |

And of course tab completion will handle all the typing of the file name, assuming you choose your file names deliberately ahead of time to make tab completion effective, in which case all you have to type is "b1 f[tab]" and bam.

182 | 183 |

Command-line Google shortcut (OS X only)

184 | 185 |

To pop open a new window in your default browser with Google search results for a given search term, do:

186 | 187 |
google "any given term"
188 | 189 |

For one-word terms, you can omit the quotes:

190 | 191 |
google term
192 | 193 |

If you already have the search term in your clipboard, you can just type:

194 | 195 |
google
196 | 197 |

(The last approach is useful for unusual command-line error messages.)

198 | 199 |

Auto-indentation

200 | 201 |

Just type as normally. This just enables built-in but underused functionality in IRB. (The IRB default auto-indentation isn't perfect, but it clobbers the living hell out of no indentation at all.)

202 | 203 |

_ special variable (like Unix shell var !!)

204 | 205 |

More activation of built-in but underused functionality in IRB. _ functions like !! in Unix, with one subtle difference. Instead of re-issuing the previous command in your history, it gives you the last result of evaluating a command. This means when you start a new IRB session, _ won't go to your history, it'll just give you nil, and it means that some commands can't be repeated exactly. Nine out of ten times, however, it's pretty much the same thing.

206 | 207 |

Note that when combined with the h! in the command history code, you basically have two synonyms for !! here. Neither one is an exact replica, but between the two of them, you should have what you need.

208 | 209 |

Extremely basic themes for Wirble syntax coloring

210 | 211 |

Utility Belt incorporates Wirble as a dependency. Wirble provides syntax coloring. Utility Belt allows you to choose between two syntax coloring themes: Wirble's default, and an alternate color set for terminals with light backgrounds. The default theme is enabled by default (duh), but if you have a terminal with a light background, you can enable the light-background theme just by putting the following line of code in your .irbrc:

212 | 213 |
UtilityBelt::Themes.background(:light)
214 | 215 |

To revert back to the default, just use this:

216 | 217 |
UtilityBelt::Themes.background(:dark)
218 | 219 |

To specify an entirely new syntax color scheme, see the source code for this gem or for Wirble.

220 | 221 |

Pascal/JavaScript-style "with" statement

222 | 223 |

I use this with RSpec's spec_helper. Instead of:

224 | 225 |
Spec::Runner.configure do |config|
226 |   config.use_transactional_fixtures = true
227 |   config.use_instantiated_fixtures  = false
228 |   config.fixture_path = RAILS_ROOT + '/spec/fixtures'
229 |   config.mock_with :flexmock
230 | end
231 | 232 |

I do this:

233 | 234 |
Spec::Runner.configure do |config|
235 |   with(config) do
236 |     use_transactional_fixtures = true
237 |     use_instantiated_fixtures  = false
238 |     fixture_path = RAILS_ROOT + '/spec/fixtures'
239 |     mock_with :flexmock
240 |   end
241 | end
242 | 243 |

Note however that this blew up once and I have no idea why. Caveat emptor, et cetera.

244 | 245 |

String#to_proc

246 | 247 |

Syntactic sugar for functional programming. (More detail here.) Rails' Symbol#to_proc is also included.

248 | 249 |
(1..3).map(&'*2') => [2, 4, 6]
250 | (1..3).map(&'[-1, _, 0]') => [[-1, 1, 0], [-1, 2, 0], [-1, 3, 0]]
251 | (1..3).map(&'x -> y -> x * y').map(&'[2]') => [2, 4, 6]
252 | (1..5).select(&'>2') => [3, 4, 5]
253 | (1..3).map(&'x -> y -> x * y').map(&'.call(2)') => [2, 4, 6]
254 | [5].map(&"(1.._).inject(&'*')") => [120]
255 | 256 |

Add and subtract Hashes with + and -

257 | 258 |
{:a => :b} + {:c => :d} = {:a => :b, :c => :d}
259 | {:a => :b, :c => :d} - {:c => :d} = {:a => :b}
260 | {:a => :b, :c => :d} - :c = {:a => :b}
261 | 262 |

You could already do this with Arrays; now you can do it with Hashes as well. (I was kinda surprised the first time I tried to do this and realized I'd have to write it myself.)

263 | 264 | 265 |

Grammatically-correct is_an? method - no more "is_a? Array" statements

266 | 267 |
>> [].is_an? Array
268 | #=> true
269 | 270 |

Most people don't care, but personally, "is_a? Array" drives me completely insane.

271 | 272 |

Object#not

273 | 274 |

Replace this:

275 | 276 |
if !response.incomplete? && !response.invalid? && response.total > 0
277 | 278 |

With this:

279 | 280 |
if response.not.incomplete? && response.not.invalid? && response.total > 0
281 | 282 |

Syntactic sugar for boolean conditions. (More detail here.)

283 | 284 |

One-character exit command

285 | 286 |
x
287 | 288 |

Because life is too short to type whole words.

289 | 290 | 291 |
292 | 293 | 296 |
297 | 298 | 299 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | == Utility Belt 2 | 3 | by Giles Bowkett (and many others) 4 | 5 | http://utilitybelt.rubyforge.org 6 | 7 | == DESCRIPTION 8 | 9 | Utility Belt is a grab-bag of tricks, tools, techniques, trifles, and toys for IRB, including convenience methods, language patches, and useful extensions. It also includes a couple command-line widgets. Its primary inspirations were an awesome gem called Wirble and a blog post by Amy Hoy called "Secrets Of The Rails Console Ninjas". 10 | 11 | (http://slash7.com/articles/2006/12/21/secrets-of-the-rails-console-ninjas) 12 | 13 | == INSTALL 14 | 15 | sudo gem install utility_belt 16 | 17 | == FEATURES 18 | 19 | * Interactively edit IRB code in your preferred text editor 20 | * Read from and write to OS X clipboard 21 | * Post your code to Pastie with one command (OS X only) 22 | * Kick-ass Unix-style history buffer 23 | * Write command history to file or vi 24 | * Grep classes and methods for strings 25 | * Verbosity controls for regular IRB and Rails console 26 | * Finder shortcuts for Rails console 27 | * Upload shortcut for Amazon S3 28 | * Command-line Amazon S3 upload script 29 | * Command-line Google shortcut (OS X only) 30 | * Auto-indentation 31 | * _ special variable (like Unix shell var !!) 32 | * Extremely basic themes for Wirble syntax coloring 33 | * Pascal/JavaScript-style "with" statement 34 | * String#to_proc 35 | * Add and subtract Hashes with + and - 36 | * Grammatically-correct is_an? method - no more "is_a? Array" statements 37 | * One-character exit command 38 | 39 | == COMMUNITY EFFORT 40 | 41 | The majority of this code was written by other people and compiled, nicked, nabbed, herded, gathered, copied, or pilfered by me (Giles Bowkett). See copyright notice for the credits. A lot of this code comes from blogs. Check out the source code for numerous links to the original posts the code came from. Thanks also to Bob Hutchison, Avdi Grimm, Marcus Derencius, Markus Prinz, Ben Bleything, Reginald Braithwaite-Lee, and Robert Berger for bug fixes, new features, documentation, and bug reports. 42 | 43 | == SYNOPSIS 44 | 45 | Utility Belt gives you a ton of new options and techniques in IRB. (You may find yourself putting its language patches in actual projects as well.) The way to use Utility Belt is to edit, or create, your .irbrc file. This is analogous to a Unix .bashrc, .tcshrc, .profile, or similar file. 46 | 47 | Windows users have a couple options. The easiest is to define an environment variable called IRBRC and set it to the full path of your irbrc (e.g. "C:\Documents and Settings\\_irbrc"). Presto, .irbrc for Windows. You could also set your HOME-Variable to any directory you want and put your ".irbrc" in there. (It needs to be called ".irbrc", "_irbrc" won't work). Since Windows Explorer won't let you create a file with a dot in the beginning, use any text editor (Notepad will do just fine) and "Save As" to save it as ".irbrc". (The quotation marks make the magic happen.) We don't recommend this if you're also using MSYS or Cygwin, as they use the same variable for their own purposes. 48 | 49 | Adding Utility Belt to your .irbrc is easy: 50 | 51 | require 'rubygems' 52 | require 'utility_belt' 53 | 54 | To use the Amazon shortcuts, you also need to set some environment variables. See the section on S3 under "Usage" for more. Also, if your terminal has a light background, you'll need to enable the light-background syntax coloring theme - see the section on themes under "Usage" for more. 55 | 56 | == USAGE 57 | 58 | Using each of Utility Belt's tools is different: 59 | 60 | == Interactively edit IRB code in your preferred text editor 61 | 62 | If your preferred text editor is vi(m), emacs, or TextMate, there are built-in commands: vi, emacs, and mate, respectively. To use another editor, use this command: 63 | 64 | edit_interactively(:the_name_of_my_editor) 65 | 66 | or 67 | 68 | edit_interactively("the name of my editor") 69 | 70 | or 71 | 72 | edit_interactively("/the/path/to/my/editor") 73 | 74 | If you're wondering why the method name is so ridiculously long, there's a story there: 75 | 76 | http://gilesbowkett.blogspot.com/2007/12/utility-belt-vs-rails.html 77 | 78 | == Read from and write to OS X or Windows clipboard 79 | 80 | In order to use Clipboard on Windows you must install the 'win32-clipboard' gem. 81 | 82 | To read: 83 | 84 | Clipboard.read 85 | 86 | To write: 87 | 88 | Clipboard.write("something") 89 | 90 | == Post your code to Pastie with one command (OS X and Windows only) 91 | 92 | You must first equip the UtilityBelt with pastie in your .irbrc: 93 | 94 | UtilityBelt.equip(:pastie) 95 | 96 | This line will also automatically equip the Clipboard, which is required to use pastie. 97 | 98 | First copy some code into your clipboard, or put it there with the Clipboard.write() class method. Then use the command: 99 | 100 | pastie 101 | 102 | or the shortcut version: 103 | 104 | pst 105 | 106 | Note that this method currently auto-formats all code as Ruby. Support for other languages is possible but not implemented yet. Also, this code is OS X and Windows only because it uses the Clipboard. (A platform-agnostic version without the clipboard aspect is certainly possible.) 107 | 108 | == Unix-style history buffer 109 | 110 | Use "h" or "history" to view your command history, and "h! 123" to re-invoke command #123 in your buffer. "h!" with no args will run the last command. 111 | 112 | == Write command history to file or vi 113 | 114 | To write your history to a file, use "history_write('/path/to/file')". To edit your history in vi, use "history_to_vi" or its shortcut alias "hvi". 115 | 116 | == Grep classes and methods for strings 117 | 118 | Classes: 119 | 120 | >> grep_classes("ixnum") 121 | #=> ["Fixnum"] 122 | 123 | >> grep_classes("num") 124 | #=> ["Bignum", "Fixnum", "Numeric", "REXML::SyncEnumerator"] 125 | 126 | Methods: 127 | 128 | >> "any arbitrary string".grep_methods("pretty") 129 | #=> ["pretty_inspect", "pretty_print_instance_variables", "pretty_print_inspect", "pretty_print", "pretty_print_cycle"] 130 | 131 | >> 32.grep_methods("*") 132 | #=> ["*", "**"] 133 | 134 | At some point it'll probably be a good idea to add regex support for these methods. 135 | 136 | == Verbosity controls for regular IRB and Rails console 137 | 138 | regular IRB: "verbose" or "v" / "quiet" or "q" 139 | 140 | Rails: "log" method turns verbosity on, there isn't actually any method for turning it off. (Might add one at some point.) 141 | 142 | == Finder shortcuts for Rails console 143 | 144 | user(:all) / user(1) 145 | 146 | instead of 147 | 148 | User.find(:all) / User.find(1) 149 | 150 | Supports arbitrarily complex finds. 151 | 152 | == Upload shortcut for Amazon S3 153 | 154 | First, define your secret keys in your environment variables: 155 | 156 | export AMAZON_ACCESS_KEY_ID='foofoofoofoofoo' 157 | export AMAZON_SECRET_ACCESS_KEY='barbarbarbarbar' 158 | 159 | (Obviously, replace those with actual values.) 160 | 161 | Then, you can use 162 | 163 | aws_upload("bucket_name","filename") 164 | 165 | To easily upload public-access files. This method will automatically connect to Amazon S3 for you, if your keys are defined in your environment variables. It also writes the resulting Amazon URL to your clipboard, if you're on OS X, so you can easily share the file with others. Note that you have to create the initial buckets manually - see amazon.rubyforge.org for details on that. 166 | 167 | A good way to use this is actually to have a default bucket, and create a further method in your .irbrc file: 168 | 169 | def my_bucket_name(filename) 170 | aws_upload("my_default_bucket",filename) 171 | end 172 | 173 | == Command-line Amazon S3 upload script 174 | 175 | Utility Belt also includes amazon, a simple command-line uploader for S3. It requires that you set your Amazon environment variables (see above). The usage is: 176 | 177 | amazon -b my_bucket_name filename other_filename 178 | 179 | (For any arbitrary number of filenames.) 180 | 181 | Anytime you want to upload a file to your default bucket on S3, for example, the "images" bucket for your blog - or the "mp3" bucket if you're running a blog like Projectionist - all you have to do is 182 | 183 | amazon -b blog_files some_file.name 184 | 185 | Or 186 | 187 | amazon --bucket blog_files some_file.name 188 | 189 | And you're good to go. Of course, if that were too many characters to type, you could always take it one step further with a shell script. For instance, in bash: 190 | 191 | alias b1="amazon --bucket my_main_bucket $1" 192 | alias b2="amazon --bucket my_other_bucket $1" 193 | 194 | And then you would only have to type: 195 | 196 | b1 file.name 197 | 198 | And of course tab completion will handle all the typing of the file name, assuming you choose your file names deliberately ahead of time to make tab completion effective, in which case all you have to type is "b1 f[tab]" and bam. 199 | 200 | == Command-line Google shortcut (OS X only) 201 | 202 | To pop open a new window in your default browser with Google search results for a given search term, do: 203 | 204 | google "any given term" 205 | 206 | For one-word terms, you can omit the quotes: 207 | 208 | google term 209 | 210 | If you already have the search term in your clipboard, you can just type: 211 | 212 | google 213 | 214 | (The last approach is useful for unusual command-line error messages.) 215 | 216 | == Auto-indentation and tab completion 217 | 218 | Just type as normally. This just enables built-in but underused functionality in IRB. (The IRB default auto-indentation isn't perfect, but it clobbers the living hell out of no indentation at all.) 219 | 220 | == _ special variable (like Unix shell var !!) 221 | 222 | More activation of built-in but underused functionality in IRB. _ functions like !! in Unix, with one subtle difference. Instead of re-issuing the previous command in your history, it gives you the last result of evaluating a command. This means when you start a new IRB session, _ won't go to your history, it'll just give you nil, and it means that some commands can't be repeated exactly. Nine out of ten times, however, it's pretty much the same thing. 223 | 224 | Note that when combined with the h! in the command history code, you basically have two synonyms for !! here. Neither one is an exact replica, but between the two of them, you should have what you need. 225 | 226 | == Extremely basic themes for Wirble syntax coloring 227 | 228 | Utility Belt incorporates Wirble as a dependency. Wirble provides syntax coloring. Utility Belt allows you to choose between two syntax coloring themes: Wirble's default, and an alternate color set for terminals with light backgrounds. The default theme is enabled by default (duh), but if you have a terminal with a light background, you can enable the light-background theme just by putting the following line of code in your .irbrc: 229 | 230 | UtilityBelt::Themes.background(:light) 231 | 232 | To revert back to the default, just use this: 233 | 234 | UtilityBelt::Themes.background(:dark) 235 | 236 | To specify an entirely new syntax color scheme, see the source code for this gem or for Wirble. 237 | 238 | == Pascal/JavaScript-style "with" statement 239 | 240 | I use this with RSpec's spec_helper. Instead of: 241 | 242 | Spec::Runner.configure do |config| 243 | config.use_transactional_fixtures = true 244 | config.use_instantiated_fixtures = false 245 | config.fixture_path = RAILS_ROOT + '/spec/fixtures' 246 | config.mock_with :flexmock 247 | end 248 | 249 | I do this: 250 | 251 | Spec::Runner.configure do |config| 252 | with(config) do 253 | use_transactional_fixtures = true 254 | use_instantiated_fixtures = false 255 | fixture_path = RAILS_ROOT + '/spec/fixtures' 256 | mock_with :flexmock 257 | end 258 | end 259 | 260 | Note however that this blew up once and I have no idea why. Caveat emptor, et cetera. 261 | 262 | == String#to_proc 263 | 264 | Syntactic sugar for functional programming. 265 | 266 | (1..3).map(&'*2') => [2, 4, 6] 267 | (1..3).map(&'[-1, _, 0]') => [[-1, 1, 0], [-1, 2, 0], [-1, 3, 0]] 268 | (1..3).map(&'x -> y -> x * y').map(&'[2]') => [2, 4, 6] 269 | (1..5).select(&'>2') => [3, 4, 5] 270 | (1..3).map(&'x -> y -> x * y').map(&'.call(2)') => [2, 4, 6] 271 | [5].map(&"(1.._).inject(&'*')") => [120] 272 | 273 | For more detail see: http://weblog.raganwald.com/2007/10/stringtoproc.html 274 | 275 | == Add and subtract Hashes with + and - 276 | 277 | {:a => :b} + {:c => :d} = {:a => :b, :c => :d} 278 | {:a => :b, :c => :d} - {:c => :d} = {:a => :b} 279 | {:a => :b, :c => :d} - :c = {:a => :b} 280 | 281 | You could already do this with Arrays; now you can do it with Hashes as well. (I was kinda surprised the first time I tried to do this and realized I'd have to write it myself.) 282 | 283 | == Grammatically-correct is_an? method - no more "is_a? Array" statements 284 | 285 | >> [].is_an? Array 286 | #=> true 287 | 288 | Most people don't care, but personally, "is_a? Array" drives me completely insane. 289 | 290 | == Object#not 291 | 292 | Replace this: 293 | 294 | if !response.incomplete? && !response.invalid? && response.total > 0 295 | 296 | With this: 297 | 298 | if response.not.incomplete? && response.not.invalid? && response.total > 0 299 | 300 | Syntactic sugar for boolean conditions. 301 | 302 | More detail here: 303 | 304 | http://blog.jayfields.com/2007/08/ruby-adding-not-method-for-readability.html 305 | 306 | == One-character exit command 307 | 308 | x 309 | 310 | Because life is too short to type whole words. 311 | 312 | == REQUIREMENTS 313 | 314 | * ReadLine 315 | * Wirble 316 | * Amazon S3 317 | * Platform 318 | * Some features require OS X 319 | 320 | == LICENSE 321 | 322 | (The MIT License) 323 | 324 | Copyright (c) 2006-2007 Giles Bowkett 325 | Portions Copyright (c) 2006-2007 Ben Bleything 326 | Portions Copyright (c) 2006-2007 Reginald Braithwaite 327 | Portions Copyright (c) 2006-2007 Gregory Brown 328 | Portions Copyright (c) 2006-2007 Jamis Buck 329 | Portions Copyright (c) 2006-2007 Mike Clark 330 | Portions Copyright (c) 2006-2007 Jay Fields 331 | Portions Copyright (c) 2005 David Heinemeier Hansson 332 | Portions Copyright (c) 2006-2007 Ara T. Howard 333 | Portions Copyright (c) 2006-2007 Pat Maddox 334 | Portions Copyright (c) 2006-2007 Marcel Molina, Jr. 335 | Portions Copyright (c) 2006-2007 Rick DeNatale 336 | Portions Copyright (c) 2006-2007 Projectionist (Marcel Molina? Chad Fowler?) 337 | Portions Copyright (c) 2006-2007 Dan Yoder 338 | 339 | Permission is hereby granted, free of charge, to any person obtaining 340 | a copy of this software and associated documentation files (the 341 | 'Software'), to deal in the Software without restriction, including 342 | without limitation the rights to use, copy, modify, merge, publish, 343 | distribute, sublicense, and/or sell copies of the Software, and to 344 | permit persons to whom the Software is furnished to do so, subject to 345 | the following conditions: 346 | 347 | The above copyright notice and this permission notice shall be 348 | included in all copies or substantial portions of the Software. 349 | 350 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 351 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 352 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 353 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 354 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 355 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 356 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 357 | --------------------------------------------------------------------------------