Skip to content

Instantly share code, notes, and snippets.

if defined?(Heroku::StaticAssetsMiddleware)
puts "Carefully adjusting Heroku::StaticAssetsMiddleware"
class Heroku::StaticAssetsMiddleware
def can_cache?(reply)
status, headers, body = reply
# if there's already a "Cache-Control" header, don't override it
body.kind_of?(Rack::File) and status.to_i == 200 and !headers.has_key?("Cache-Control")
end
end
end
@mdub
mdub / sass_stylesheets.rb
Created December 15, 2010 11:57
serve *.sass using Rack::File
# app/metal/sass_stylesheets.rb
#
# This Rails metal keeps Sass stylesheets up-to-date, and serves them using Rack.
#
# Unlike the default Sass/Rails integration, this happily supports a
# Sass::Plugin.options[:css_location] outside the Rails.public_path.
#
class SassStylesheets
class << self
@mdub
mdub / chef-bootstrap.rb
Created October 29, 2010 01:08
bootstrap a remote machine as a Chef server/client
#!/usr/bin/env ruby
require "rubygems"
require "erb"
require "fileutils"
require "json"
require "net/ssh"
require "net/scp"
require "optparse"
require "capybara"
Capybara.app_host = "http://dogbiscuit.org"
session = Capybara::Session.new(:culerity, "dummy app")
session.visit("/")
puts "URL: #{session.current_url}"
puts "\nArticles:"
session.all('//h3').each do |e|
sudo cp /usr/local/Cellar/mysql/5.1.41/com.mysql.mysqld.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist
sudo cp /usr/local/Cellar/postgresql/8.4.2/org.postgresql.postgres.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/org.postgresql.postgres.plist
sudo cp /usr/local/Cellar/mongodb/1.2.0-x86_64/org.mongodb.mongod.plist /Library/LaunchDaemons/
sudo launchctl load -w /Library/LaunchDaemons/org.mongodb.mongod.plist
@mdub
mdub / rvm-default-ruby
Created January 18, 2010 11:47
rvm-default-ruby
#!/bin/sh
# For easy rvm/TextMate integration, point your "TM_RUBY" Shell Variable at this script
# e.g. TM_RUBY=/Users/whaevuh/bin/rvm-default-ruby
source $HOME/.rvm/config/default
exec ruby "$@"
def stub_rest_client(method, url = nil, options = {}, &block)
options = options.dup
options[:method] = method
options[:url] = url.to_s if url
stub(RestClient::Request).execute(hash_including(options), &block)
end
# This Rack middleware prevents API consumers from exceeding their allocated requests-per-minute limit.
#
# Per-minute usage allocations divided by 6 to give a 10-second allocation. If a consumer goes over-limit
# for a particular period, they are temporarily denied access.
class PreventDenialOfService
class << self
def call(env)
new(env).call
# A Hash derivative that is automatically cleared every so often
class PeriodicallyClearedHash
def initialize(period, &default_value_calculator)
@period = period.to_i
@default_value_calculator = default_value_calculator || lambda { nil }
end
attr_reader :period