Skip to content

Instantly share code, notes, and snippets.

View jwo's full-sized avatar

Jesse Wolgamott jwo

View GitHub Profile
@jwo
jwo / deploy.rb
Created January 2, 2012 19:58
Capistrano with Unicorn Reloading
set :application, "yyyyyyyyyyy"
set :repository, "here-be-your-githubs"
set :scm, :git
set :branch, "master"
set :user, "xxxxxxxx"
set :scm_verbose, true
default_run_options[:pty] = true
set :deploy_via, :remote_cache
ssh_options[:forward_agent] = true
@jwo
jwo / nginx.conf
Created January 2, 2012 20:03
nginx config for unicorn
# you generally only need one nginx worker unless you're serving
# large amounts of static files which require blocking disk reads
worker_processes 1;
user nobody nogroup; # for systems with a "nogroup"
pid /tmp/nginx.pid;
error_log /tmp/nginx.error.log;
events {
worker_connections 1024;
@jwo
jwo / unicorn.rb
Created January 2, 2012 20:07
Unicorn Production config file
#### This is for mongoid, so the active-record stuff is commented out.
#### Uncomment in before/after fork to make this happy
worker_processes 4
user "unprivileged_user", "unprivileged_group"
working_directory "/u/apps/yourappdirectory/current" # available in 0.94.0+
listen "/tmp/.sock", :backlog => 64
listen 8080, :tcp_nopush => true
@jwo
jwo / kata.rb
Created January 11, 2012 14:35
Kata Four: Data Munging
# Houston Ruby group solution for http://codekata.pragprog.com/2007/01/kata_four_data_.html
require 'rspec'
class CalculateSpread
def for_file(filename)
smallest_day, smallest_spread = nil, infinity
File.readlines(filename).each do |line|
next unless valid_line?(line)
@jwo
jwo / api_base_controller.rb
Created January 18, 2012 14:04
Protests on RAILS
class Api::BaseController < ApplicationController
respond_to :json
skip_before_filter :protest_sopa
protected
def unauthorized!
render :text=>"Unauthorized Action", :status=>:unauthorized
end
end
@jwo
jwo / dr_spec.rb
Created February 29, 2012 16:54
DRY Mongoid modules
#http://jessewolgamott.com/blog2012/02/29/the-one-where-we-dry-up-mongoid-and-rspec-using-shared-examples-and-modules/
require 'spec_helper'
module Contactable
def self.included(receiver)
receiver.class_eval do
field :first_name, type: String
field :last_name, type: String
@jwo
jwo / admin_domain.rb
Created March 23, 2012 15:09
ActiveAdmin on admin domain
class AdminDomain
def self.matches?(request)
request.subdomain =~ /admin/
end
end
@jwo
jwo / .rspec
Created March 29, 2012 01:04 — forked from coreyhaines/.rspec
Loading just active record
--colour
-I app
@jwo
jwo / message.rb
Created April 30, 2012 16:13
Sample mailbox delivery code for Ruby Off Rails
class Message
def deliver_to(mailbox)
mailbox.new_mail(self)
end
end
class Mailbox
def initialize
@jwo
jwo / gist:2585904
Created May 3, 2012 14:11 — forked from unnitallman/gist:944011
sqlite with activerecord outside rails
require 'active_record'
require 'logger'
ActiveRecord::Base.logger = Logger.new(STDERR)
ActiveRecord::Base.establish_connection(
adapter: "sqlite3",
database: ":memory:"
)