$ sudo gem install bundlemate
If it isn’t showing up because Rubyforge’s gem cache hasn’t updated, you can grab it directly from my new personal Rubyforge project page.
Run bundlemate help for instructions.
require 'timeout'
class TimeoutProxy
include Timeout
def initialize(receiver, timeout_in_seconds)
@receiver = receiver
@timeout_in_seconds = timeout_in_seconds
end
def method_missing(method, *args, &block)
timeout(@timeout_in_seconds) do
@receiver.send(method, *args, &block)
end
end
end
class Object
def with_timeout(timeout_in_seconds)
TimeoutProxy.new(self, timeout_in_seconds)
end
end
# EXAMPLE:
# class Foo
# def self.some_long_running_method
# sleep 10; puts 'done';
# end
# end
#
# # without timeout
# Foo.some_long_running_method
# #=> 'done'
#
# # with timeout
# Foo.with_timeout(3).long_running_method
# #=> raises Timeout::Error
I was having some problems with the Ruby and Curl scripts on Pastie so I hacked together a quick script of my own. It takes the text you want to paste from STDIN and sends it to pastie (run pastie -h for options) and if successful it prints the resulting pastie URL.
Its easy to chain common unix commands together with the pastie script - try this to send the contents of a file to pastie then open the resulting paste in your default browser (OSX/*nix):
$ cat ~/somefile.html | pastie -f html | xargs open