Google calculator response to "once in a blue moon"

Posted by root Fri, 04 Jul 2008 13:46:00 GMT

Results in the following:

once in a blue moon = 1.16699016 × 10-8 hertz

Can be tested here

Tags  | no comments

Google Chart API

Posted by root Mon, 30 Jun 2008 07:33:00 GMT

Charts for a map (in this example I’ve included Spain, France, Italy and Norway):



more about this API

Posted in  | Tags  | no comments

mkdir && cd to it

Posted by root Mon, 16 Jun 2008 12:49:00 GMT

# negative - spawning a new shell
mkdir -p $1 && cd $1 && $SHELL

Posted in  | Tags  | no comments

Getting an indication of the number of arguments accepted by a method

Posted by root Mon, 16 Jun 2008 08:57:00 GMT

class Object
  def arguments?(*methods)
    methods.each do |method|
      begin
        rval = self.method(method).arity
        if rval > 0
          puts "'#{method}' takes fixed (#{rval}) number of argument"
        elsif rval < 0
          puts "'#{method}' takes variable number of arguments"
        elsif rval == 0
          puts "'#{method}' takes no arguments"
        end
      rescue
       puts $!
      end
    end
  end
end

String.new.arguments?(:size, :to_i, :scan, :flatten)

www.ruby-doc.org arity

Posted in  | Tags  | no comments

Fun with String class methods

Posted by root Sat, 14 Jun 2008 13:45:00 GMT

class MyString < String
  # not really useful
  alias + concat

  # emulates Array '*' method
  def *(string)
    self.split('').inject('') do |s1,c|
      s1 + c + string
    end
  end

  # emulates Array '-' method
  def /(string)
    (self.split('') - string.split('')).to_s
  end

  # chars' delimiter
  def delimiter(string)
    self.*(string).sub /.$/, ''
  end

end

a = MyString.new("abcdef")
b = MyString.new("ABCDEF")

puts a * ':'
puts a / (b + "a")
puts a.delimiter(":")

#a:b:c:d:e:f:
#bcdef
#a:b:c:d:e:f

Posted in  | Tags ,  | no comments

Older posts: 1 2 3 ... 11