Skip to content

Instantly share code, notes, and snippets.

View condition_builder.rb
# 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 Jul 5, 2011
Drop Down and Fade out Flash Messages
View _flash.sass
/* 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 Jul 6, 2011
MacVim - Find in files
View gist:1067444
:vimgrep regex path
#example to find all ruby files using "belongs"to
:vimgrep /belongs_to/ **/*.rb
:cnext
:cprevious
@jwo
jwo / application.html
Created Jul 15, 2011
Dynamically load javascript source files
View application.html
<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 Sep 30, 2011
API JSON authentication with Devise
View registrations_controller.rb
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 Oct 12, 2011
Fast Rails Burro Test -- Modules
View burrito_delicious_policy.rb
class BurritoDeliciousPolicy
def delicious?(burrito)
burrito.guacamole?
end
end
@jwo
jwo / burro.rb
Created Oct 12, 2011
Fast Rails Tests -- Test in Isolation
View burro.rb
class Burro < ActiveRecord::Base
#guacamole defined on schema
def delicious?
BurroDeliciousPolicy.new(self).delicious?
end
end
@jwo
jwo / APIcall.json
Created Dec 6, 2011
ZenCoder HTML5 creation for videos.com
View APIcall.json
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 Dec 19, 2011
ActiveAdmin support for Mongoid (monkey path)
View active_admin_support_for_mongoid.rb
require "active_admin"
require "active_admin/resource_controller"
module ActiveAdmin
class Namespace
# Disable comments
def comments?
false
end
end
View gist:1546140
#!/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