Skip to content

Instantly share code, notes, and snippets.

View fairchild's full-sized avatar

Michael Fairchild fairchild

  • Procore
  • California
View GitHub Profile
@jeffrafter
jeffrafter / foo.rb
Created February 10, 2009 05:40
Simple resource access using HTTParty and avoiding the weight of ActiveResource
require File.join(File.dirname(__FILE__), 'resource_party')
class Foo < ResourceParty::Base
base_uri Lokii::Config.remote
route_for 'foos'
resource_for 'foo'
end
@fairchild
fairchild / dht_api_sample.rb
Created February 27, 2009 21:16
proposed API for ditributed has table
# sample skeleton for a ruby API based on the ideas from http://www.oceanstore.org/publications/papers/pdf/iptps03-api.pdf
class DistributeKeyBasedRouter
def initialize(deliver_to_class, deliver_class_method = :delivered)
@delivery_callback_class = deliver_to_class
@delivery_callback_method = deliver_class_method
end
Warden::Manager.serialize_into_session{|user| user.id }
Warden::Manager.serialize_from_session{|id| User.get(id) }
Warden::Manager.before_failure do |env,opts|
# Sinatra is very sensitive to the request method
# since authentication could fail on any type of method, we need
# to set it for the failure app so it is routed to the correct block
env['REQUEST_METHOD'] = "POST"
end
# stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb
# and made a lot more robust by me
# this implementation uses erb by default. if you want to use any other template mechanism
# then replace `erb` on line 13 and line 17 with `haml` or whatever
module Sinatra::Partials
def partial(template, *args)
template_array = template.to_s.split('/')
template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
options = args.last.is_a?(Hash) ? args.pop : {}
options.merge!(:layout => false)
=== Epic Snow Leopard Upgrayyyyd Guide ===
Son, you’re now living in the land of 64-bit systems.
That means that some of your 32-bit shit is now broken.
Not all is lost.
== Fixing MySQL weirdness
@tomlea
tomlea / gist:207938
Created October 11, 2009 22:55
This is very rough and ready.
require "net/http"
# Example Usage:
#
# use Rack::Proxy do |req|
# if req.path =~ %r{^/remote/service.php$}
# URI.parse("http://remote-service-provider.com/service-end-point.php?#{req.query}")
# end
# end
#
@defunkt
defunkt / resque.py
Created November 3, 2009 19:49
Resque client in Python
from redis import Redis
import simplejson
class Resque(object):
"""Dirt simple Resque client in Python. Can be used to create jobs."""
redis_server = 'localhost:6379'
def __init__(self):
host, port = self.redis_server.split(':')
self.redis = Redis(host=host, port=int(port))
@gavinheavyside
gavinheavyside / trivial_file_upload_service.rb
Created November 3, 2009 20:09
Trivial file upload service using Sinatra
require 'rubygems'
require 'sinatra'
require 'fileutils'
# upload with:
# curl -v -F "data=@/path/to/filename" http://localhost:4567/user/filename
post '/:name/:filename' do
userdir = File.join("files", params[:name])
@fairchild
fairchild / bundle-to-ebs.sh
Created December 5, 2009 23:32
2 scripts that can be used to create an bootable EBS from a running instance. ami-4205e72b created with this process
#!/bin/bash -xe
EBS_DEVICE='/dev/sdh'
INSTANCE_ID=$1
AKI=${2:-'aki-5f15f636'}
ARI=${3:-'ari-0915f660'}
ARCH=${4:-'i386'}
SIZE=${5:-10}
AZ=${6:-'us-east-1d'}
NAME=${7:-"ami-from-$INSTANCE_ID"}
@samgranieri
samgranieri / .gitignore
Created January 29, 2010 04:55
Rails 3 Capistrano Notes
db/*.sqlite3
log/*.log
tmp/**/*
bin/*
vendor/gems/ruby/1.8/*
!vendor/gems/ruby/1.8/cache/