Skip to content

Instantly share code, notes, and snippets.

@lgs
lgs / gist:3068455
Created July 7, 2012 22:50 — forked from adamlwatson/gist:1371577
Mongoid connection pooling in Goliath
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
@loren
loren / rails_routing_invalid_chars_fix.rb
Created August 17, 2012 17:37
Fix for ArgumentError: invalid byte sequence in UTF-8
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?
@mranallo
mranallo / nginx.rb
Created August 27, 2012 19:09
Homebrew recipe for nginx with upload modules
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'
# 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?)
@woods
woods / enable_trim.sh
Created August 12, 2012 20:19
Enable TRIM support for 3rd Party SSDs. Works for Mountain Lion.
#!/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
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
@cyberwombat
cyberwombat / CORS Configuration
Created November 1, 2012 19:18
JQuery file upload plugin (blueimp) with NodeJs Express3 directly to Amazon S3 with public access
<?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>
namespace :db do
task :create_indexes => :environment do
#
begin
Rails.application.eager_load!
rescue Object => e
end
#
begin
@kgrz
kgrz / faraday-em-http.rb
Created November 10, 2012 16:01 — forked from igrigorik/faraday-em-http.rb
using Faraday with EM-Synchrony & EM-Http
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
@douglas
douglas / trim_enabler.sh
Created November 16, 2012 20:11 — forked from return1/trim_enabler.txt
TRIM Enabler for OS X Mountain Lion 10.8.2 or higher
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!