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
# This is a trivial HTTP proxy server, intended for use as a troubleshooting tool | |
# ONLY (not for real, actual, production use). I wrote this because I couldn't find | |
# a simple HTTP proxy that I could use to test HTTP proxy support in Net::SSH. | |
# | |
# This code is in the public domain, so do with it what you will! | |
require 'socket' | |
server = TCPServer.new('127.0.0.1', 8080) | |
client = server.accept |
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
# rake db:fixtures:dump | |
namespace :db do | |
namespace :fixtures do | |
desc 'Create YAML test fixtures from data in an existing database. | |
Defaults to development database. Set RAILS_ENV to override.' | |
task :dump => :environment do | |
sql = "SELECT * FROM %s" | |
skip_tables = ["schema_info", "schema_migrations"] |
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
module Paperclip | |
class ThumbnailWithDimensions < Thumbnail | |
def initialize(file, options = {}, attachment = nil) | |
super | |
attachment.instance.width = @current_geometry.width | |
attachment.instance.height = @current_geometry.height | |
end | |
end | |
end | |
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 |
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
/* 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
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
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
>> 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
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 |
OlderNewer