Skip to content

Instantly share code, notes, and snippets.

@gerred
gerred / gist:667985
Created November 8, 2010 17:37
nginx.conf for reverse proxying
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
@gerred
gerred / gist:738576
Created December 13, 2010 02:13
quick node/NPM install
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install
curl http://npmjs.org/install.sh | sh
@gerred
gerred / double_polymorphism.rb
Created March 5, 2011 00:13
Doubly Polymorphic Join Models, for fun and profit
class Delivery < ActiveRecord::Base
belongs_to :deliverable, :polymorphic => true
belongs_to :receivable, :polymorphic => true
has_many :delivery_impressions
has_many :users, :through => :delivery_impressions
belongs_to :sender, :class_name => 'User', :foreign_key => :sender_id
end
class DeliveryImpression < ActiveRecord::Base
set :rails_env, :production
set :unicorn_binary, "/usr/bin/unicorn"
set :unicorn_config, "#{current_path}/config/unicorn.rb"
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && #{try_sudo} #{unicorn_binary} -c #{unicorn_config} -E #{rails_env} -D"
end
task :stop, :roles => :app, :except => { :no_release => true } do
{":(":{"code":":(","description":"frown","image":"http://sae.tweek.us/static/images/emoticons/frown.gif","height":15,"width":15,"added":1255900959},":)":{"code":":)","description":"smile","image":"http://sae.tweek.us/static/images/emoticons/smile.gif","height":15,"width":15,"added":1255900959},":11tea:":{"code":":11tea:","description":"11:00 drink tea every day","image":"http://sae.tweek.us/static/images/emoticons/emot-11tea.gif","height":25,"width":32,"added":1255900960},":3:":{"code":":3:","description":"kitty face","image":"http://sae.tweek.us/static/images/emoticons/emot-3.gif","height":18,"width":15,"added":1255900960},":a2m:":{"code":":a2m:","description":"Ass to Mouth","image":"http://sae.tweek.us/static/images/emoticons/emot-a2m.gif","height":19,"width":40,"added":1255900960},":aaa:":{"code":":aaa:","description":"my mouth is opening oh no","image":"http://sae.tweek.us/static/images/emoticons/emot-aaa.gif","height":15,"width":15,"added":1255900960},":aaaaa:":{"code":":aaaaa:","description":"AAAAAAHHHH
after_create :destroy_orphan
def destroy_orphan
destroy if state == "cart"
end
handle_asynchronously :destroy_orphan, :run_at => Proc.new { 48.hours.from_now }
@gerred
gerred / gist:934456
Created April 21, 2011 13:20
A Little Bunny Example
require 'bunny'
b = Bunny.new(:logging => true)
b.start
exchange = b.exchange('hello_reddirt', :type => :fanout)
q = b.queue('my_queue')
q.bind(exchange)
Some brief instructions on how to use Sprocket 2 in Rails to get CoffeeScript
powered JS and SASS powered CSS with YUI compression all via the magic of rack.
This stuff will be native in Rails 3.1 and the layout of the files on the
filesystem will be different but this guide will get you working with it
while we wait for all that to finalize.
Ignore the number prefixes on each file. This is just to ensure proper order in the Gist.
It's based on eric1234 gist https://gist.github.com/911003. ijust made it 3.1 compliant in terms of convention
function Blame()
let g:old_ft=&ft
let g:old_fname=expand('%')
vnew
exec "0r!git blame " . g:old_fname
exec "set ft=" . g:old_ft
normal! zt
endfunction
command! -nargs=0 Blame call Blame()
@gerred
gerred / DungeonGame.scala
Created May 2, 2011 14:37 — forked from d-smith/DungeonGame.scala
Game Sample - Learn Scala in 2 Days
trait Item {
val weight: Int
val description: String
val name: String
}
class Action