This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e = Event.new | |
=> #<Event _id: 4d545395223e17aeca000004> | |
"ZOMG!!!" if e.creator | |
=> nil | |
e.creator.object_id | |
=> 4 | |
e.creator = nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> proc {||}.arity | |
=> 0 | |
>> proc {}.arity | |
=> -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prototype's scrollTo() for jQuery. | |
// | |
// Usage: | |
// $('#element').scrollTo(); | |
// | |
$.fn.scrollTo = function() { | |
var offset = this.offset(); | |
window.scrollTo(offset['left'], offset['top']); | |
return this; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder