Skip to content

Instantly share code, notes, and snippets.

require 'drb'
# ruby-serial was crashing Shoes so run serial code in another process using DRb to
# communicate the state of the controller.
pid = Process.fork { exec('ruby', 'controller.rb') }
Shoes.app :width => 938, :height => 768, :resizable => false do
# Start the DRb client.
DRb.start_service
@phorsfall
phorsfall / gist:821394
Created February 10, 2011 21:36
Hmmph, Mongoid
e = Event.new
=> #<Event _id: 4d545395223e17aeca000004>
"ZOMG!!!" if e.creator
=> nil
e.creator.object_id
=> 4
e.creator = nil
# Also see: http://timeless.judofyr.net/tailin-ruby
# Requires Ruby 1.9:
fib = lambda do |i, n = 1, result = 0|
if i == -1
result
else
i, n, result = i - 1, n + result, n
redo
require 'curses'
# Innit.
Curses::init_screen
# Don't echo keypress on the console.
Curses::noecho
# Create a centered window, of size:
height, width = 32, 64
>> proc {||}.arity
=> 0
>> proc {}.arity
=> -1
@phorsfall
phorsfall / gist:425554
Created June 4, 2010 15:34
Capybara Timeout Money Patch
class Capybara::Driver::RackTest
private
def follow_redirects!
Capybara::WaitUntil.timeout(4) do
redirect = response.redirect?
follow_redirect! if redirect
not redirect
end
rescue Capybara::TimeoutError
class Hash
def /(key_path)
keys = key_path.split(".")
keys.length > 1 && self[keys[0]] ? self[keys[0]]/keys[1..-1].join(".") : self[key_path]
end
end
# h = { "end" => { "of" => { "the" => { "rainbow" => "gold" }}}}
# h/"end.of.the.rainbow"
/* Nurphy.com textarea auto-resize
*
* Based on implementation here:
* http://stackoverflow.com/questions/7477/autosizing-textarea
*
* Hidden textarea technique inspired by:
* http://james.padolsey.com/javascript/jquery-plugin-autoresize/
*
* Stack Overflow version inspired by:
* http://github.com/jaz303/jquery-grab-bag/blob/63d7e445b09698272b2923cb081878fd145b5e3d/javascripts/jquery.autogrow-textarea.js
// Prototype's scrollTo() for jQuery.
//
// Usage:
// $('#element').scrollTo();
//
$.fn.scrollTo = function() {
var offset = this.offset();
window.scrollTo(offset['left'], offset['top']);
return this;
};
class Version < Struct.new(:version_string)
include Comparable
def [](version_string)
new(version_string)
end
def to_a
version_string.split(".").map { |s| s.to_i }
end