Skip to content

Instantly share code, notes, and snippets.

View jwo's full-sized avatar

Jesse Wolgamott jwo

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / gist:1546140
Created January 1, 2012 03:25 — forked from mguterl/gist:308216
#!/bin/sh
set -u
set -e
# Example init script, this can be used with nginx, too,
# since nginx and unicorn accept the same signals
# Feel free to change any of the following variables for your app:
APP_ROOT=/home/deploy/public_html/rm/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
ENV=production
@jwo
jwo / active_admin_support_for_mongoid.rb
Created December 19, 2011 15:30
ActiveAdmin support for Mongoid (monkey path)
require "active_admin"
require "active_admin/resource_controller"
module ActiveAdmin
class Namespace
# Disable comments
def comments?
false
end
end
@jwo
jwo / APIcall.json
Created December 6, 2011 21:43
ZenCoder HTML5 creation for videos.com
POST https://app.zencoder.com/api/v2/jobs HTTP/1.1
Accept: application/json
Content-Type: application/json
{
"api_key": "API_KEY_HERE",
"input": "PUBLIC_FILE_URL_HERE",
"private": true,
"output": [
{
@jwo
jwo / burro.rb
Created October 12, 2011 12:25
Fast Rails Tests -- Test in Isolation
class Burro < ActiveRecord::Base
#guacamole defined on schema
def delicious?
BurroDeliciousPolicy.new(self).delicious?
end
end