This file contains hidden or 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
# 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 | |
This file contains hidden or 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 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 |
This file contains hidden or 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
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 file contains hidden or 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
#!/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 "$@" |
This file contains hidden or 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
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 |
This file contains hidden or 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 "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| |
This file contains hidden or 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
#!/usr/bin/env ruby | |
require "rubygems" | |
require "erb" | |
require "fileutils" | |
require "json" | |
require "net/ssh" | |
require "net/scp" | |
require "optparse" |
This file contains hidden or 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
# 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 |
This file contains hidden or 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
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 |
This file contains hidden or 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
# Tasks designed to run ON Heroku | |
namespace :pgbackup do | |
def pgbackup_client | |
require "pgbackups/client" | |
@pgbackup_client ||= PGBackups::Client.new(ENV.fetch("PGBACKUPS_URL")) | |
end | |
task :capture do | |
db = "DATABASE_URL" |
OlderNewer