Skip to content

Instantly share code, notes, and snippets.

View jwo's full-sized avatar

Jesse Wolgamott jwo

View GitHub Profile
# Condition Builder for ActiveRecord
#
# (c) 2005-2006 Ezra Zygmuntovic, Jens-Christian Fischer and Duane Johnson
# distributed under the same license as Ruby On Rails
#
# Version 1.1
#
# Jan 4, 2007: Added "AND" and "OR" using 'and' and 'or'. Also added ability to use sub-conditions
# e.g.
# Condition.block { |c|
@jwo
jwo / _flash.sass
Created July 5, 2011 19:39
Drop Down and Fade out Flash Messages
/* flash-messages
#flash
left: 0
margin: 0 auto
position: absolute
text-align: center
top: 0
width: 100%
z-index: 1000
@jwo
jwo / gist:1067444
Created July 6, 2011 15:00
MacVim - Find in files
:vimgrep regex path
#example to find all ruby files using "belongs"to
:vimgrep /belongs_to/ **/*.rb
:cnext
:cprevious
@jwo
jwo / application.html
Created July 15, 2011 15:47
Dynamically load javascript source files
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script>
<script>
//<![CDATA[
window.jQuery || document.write("<script src='/javascripts/jquery.min.js'>\x3C/script>")
//]]>
</script>
@jwo
jwo / registrations_controller.rb
Created September 30, 2011 23:11
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@jwo
jwo / burrito_delicious_policy.rb
Created October 12, 2011 12:13
Fast Rails Burro Test -- Modules
class BurritoDeliciousPolicy
def delicious?(burrito)
burrito.guacamole?
end
end
@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
@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 / 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 / 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