Skip to content

Instantly share code, notes, and snippets.

# 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
# 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"]
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
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
// Prototype's scrollTo() for jQuery.
//
// Usage:
// $('#element').scrollTo();
//
$.fn.scrollTo = function() {
var offset = this.offset();
window.scrollTo(offset['left'], offset['top']);
return this;
};
/* 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
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"
@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
>> proc {||}.arity
=> 0
>> proc {}.arity
=> -1
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