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 'em-synchrony/em-mongo' | |
require 'mongoid' | |
mongoid_conn = Mongo::Connection.new 'localhost', 27017, :pool_size => 10 | |
Mongoid.configure do |config| | |
begin | |
config.master = mongoid_conn.db('dbname') | |
rescue Exception=>err | |
abort "An error occurred while creating the mongoid connection pool: #{err}" | |
end |
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 'action_dispatch/routing/route_set' | |
# Based on https://gist.github.com/2830082 | |
module ActionDispatch | |
module Routing | |
class RouteSet | |
class Dispatcher | |
def call_with_invalid_char_handling(env) | |
uri = CGI::unescape(env["REQUEST_URI"].force_encoding("UTF-8")) | |
# If anything in the REQUEST_URI has an invalid encoding, then raise since it's likely to trigger errors further on. | |
return [400, {'X-Cascade' => 'pass'}, []] if uri.is_a?(String) and !uri.valid_encoding? |
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 'formula' | |
class Nginx < Formula | |
homepage 'http://nginx.org/' | |
url 'http://nginx.org/download/nginx-1.2.3.tar.gz' | |
sha1 '98059ae08ebbfaaead868128f7b66ebce16be9af' | |
devel do | |
url 'http://nginx.org/download/nginx-1.3.5.tar.gz' | |
sha1 'ce0245295f23a54f10d916eb6b7b34469d0618a1' |
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
# Wrap a fiber around app_call | |
Fiber.new{ | |
# [...] | |
# Below is modified from event_machine/client.rb, in def app_call input, | |
# but let's forget about :async for now. | |
# In APP.call, it would call Fiber.yield whenever we're waiting for data. | |
status, headers, body = APP.call(@env.merge!(RACK_DEFAULTS)) | |
# The response is fully ready at this point. | |
ev_write_response(status, headers, body, @hp.next?) |
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/bash | |
# | |
# Enable TRIM support for 3rd Party SSDs. Works for Mountain Lion | |
# | |
# Source: http://digitaldj.net/2011/07/21/trim-enabler-for-lion/ | |
set -e | |
set -x | |
# Back up the file we're patching |
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 'queue' | |
# Simplified version of the pooling from datamapper's data_objects. | |
# https://github.com/datamapper/do/blob/master/data_objects/lib/data_objects/pooling.rb | |
class Moped::Session | |
class << self | |
alias new __new | |
end | |
@__pool_lock = Mutex.new |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> | |
<CORSRule> | |
<AllowedOrigin>*</AllowedOrigin> | |
<AllowedMethod>GET</AllowedMethod> | |
<AllowedMethod>POST</AllowedMethod> | |
<AllowedMethod>PUT</AllowedMethod> | |
<MaxAgeSeconds>3000</MaxAgeSeconds> | |
<AllowedHeader>*</AllowedHeader> | |
</CORSRule> |
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
namespace :db do | |
task :create_indexes => :environment do | |
# | |
begin | |
Rails.application.eager_load! | |
rescue Object => e | |
end | |
# | |
begin |
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 'faraday' | |
require 'net/http' | |
require 'pp' | |
# Repos: | |
# https://github.com/technoweenie/faraday | |
# https://github.com/pengwynn/faraday_middleware | |
# Blog posts: | |
# http://adventuresincoding.com/2010/09/writing-modular-http-client-code-with-faraday |
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 /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage.original | |
sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x54)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage | |
sudo touch /System/Library/Extensions/ | |
# now reboot! |