View periodically_cleared_hash.rb
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
# 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 | |
View prevent_denial_of_service.rb
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 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 |
View stub_rest_client.rb
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
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 |
View rvm-default-ruby
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
#!/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 "$@" |
View gist:289701
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
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 |
View capybara-example.rb
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 "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| |
View example_pact_matcher_spec.rb
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 "spec_helper" | |
require "pact/matchers" | |
require "pact/matchers/unix_diff_formatter" | |
require "term/ansicolor" | |
RSpec::Matchers.define :match_data do |expected| | |
match do |actual| | |
difference(actual).empty? |
View chef-bootstrap.rb
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
#!/usr/bin/env ruby | |
require "rubygems" | |
require "erb" | |
require "fileutils" | |
require "json" | |
require "net/ssh" | |
require "net/scp" | |
require "optparse" |
View sass_stylesheets.rb
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
# 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 |
View heroku_static_cache_control.rb
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
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 |
OlderNewer