Skip to content

Instantly share code, notes, and snippets.

@apeckham
apeckham / gist:49172
Created January 19, 2009 21:02
Delegate all methods
class BrowsePage
attr_reader :collection
def initialize(collection)
@collection = collection
end
def method_missing(method, *args, &block)
@collection.send method, *args, &block
end
@apeckham
apeckham / gist:64057
Created February 13, 2009 19:28
Ignore some columns
def self.columns
ignored_columns = ["state_changed"]
super.delete_if { |column| ignored_columns.include?(column.name) }
end
@apeckham
apeckham / ExpiringMemoryStore.rb
Created June 1, 2009 03:29
MemoryStore that supports expires_in
class ExpiringMemoryStore < ActiveSupport::Cache::MemoryStore
def read(name, options = nil)
out = super(name, options)
return if out.nil?
return if out.first && out.first < Time.now
return out.last
end
def write(name, value, options = {})
@apeckham
apeckham / BlackHoleStore.rb
Created June 1, 2009 03:29
Disables Rails.cache for testing like http://gist.github.com/104946, but only overrides write
class BlackHoleStore < ActiveSupport::Cache::MemoryStore
def write(*args)
end
end
def wait_for_server
time_out_at = Time.now + 30.seconds
loop do
raise "Server didn't start after 30 seconds" if Time.now > time_out_at
begin
open 'http://localhost:2000/'
return
rescue Errno::ECONNREFUSED, Errno::ECONNRESET
end
To use RubyMine, RVM (Ruby Version Manager) and REE (Ruby Enterprise Edition) on Snow Leopard, I had to:
sudo ln -s /Users/yourname/.rvm/ruby-enterprise-1.8.6-20090610 /opt/
Then, in RubyMine Preferences, select Ruby SDK and Gems, Add SDK... and choose /opt/ruby-enterprise-1.8.6-20090610/bin/ruby
And put this into ~/.MacOSX/environment.plist. Then log out and log back in.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
yum install curl-devel krb5-devel e2fsprogs-devel libidn-devel openssl-devel zlib-devel
# http://groups.google.com/group/curb---ruby-libcurl-bindings/browse_thread/thread/cb50d150424b4fe5
class PidFile
attr_reader :path
def initialize(path)
@path = path
end
def write
file = File.open(@path, "w")
file << Process.pid
var TRACK_URL = 'http://www.google-analytics.com/ga.js';
var TRACK_TRIES = 0;
function Monitor() {
if ("_gat" in window) {
window.clearInterval(Monitor.INTERVAL);
Monitor.INTERVAL = null;
var A = _gat._getTracker("UA-176427-3");
A._initData();
A._trackPageview()
@apeckham
apeckham / stylesheet_cdata_section.rb
Created March 18, 2010 08:24
cdata_section for stylesheets/css
def stylesheet_cdata_section(content)
"\n/*#{cdata_section("*/\n#{content}\n/*")}*/\n"
end