Skip to content

Instantly share code, notes, and snippets.

View jbarnette's full-sized avatar

John Barnette jbarnette

View GitHub Profile
# $ source README.sh
which redis-server && \
which sqlite3 && \
which java && \
which mongo && \
bundle install && \
rake test docs && \
open doc/index.html
@jbarnette
jbarnette / example.rb
Created April 6, 2011 14:55
A naïve state machine for ActiveRecord. Ruby 1.9.
require "stateful"
class Folder < ActiveRecord::Base
include Stateful
# ...
stateful do
state :active
state :inactive
########################################################################
### Rakefile for encrypted passwords
########################################################################
#
# Here's a little Rakefile to manage your encrypted password file! It's
# really easy to use:
#
# 1) put the email addresses of the keys you want in AUTHORIZED_USERS
# 2) create a passwords.txt (and ignore it in your SCM)
# 3) run `rake passwords:encrypt`
# When anything, including nil, is a valid param and you need
# a clear way to know if a param was set or not.
def foo a, b = (b_was_not_passed = true; nil)
result = [a]
result << b unless b_was_not_passed
result
end
diff --git a/Rakefile b/Rakefile
index 0794562..2aa2c18 100644
--- a/Rakefile
+++ b/Rakefile
@@ -6,6 +6,7 @@ require 'rubygems'
require 'rubygems/package_task'
require 'hoe'
+Hoe::RUBY_FLAGS.insert 0, "--disable-gems "
def run
begin
started
result = constantize(object).send(method_name, *args)
Whatever::Job.keep? ? completed : destroy
result
rescue Exception => exception
failed(exception.message)
end
end
################################################################################
### M E T H O D N A M E :: address ############################################
### A R G U M E N T S :: separator[String] ##################################
### R E T U R N S :: String #############################################
### A U T H O R :: Alan Smithee #######################################
### D A T E :: 1989-10-31 #########################################
################################################################################
def address separator
puts "Hello, #{ENV['USER']}! I'm a gist!"
class Intercession
# Duh.
VERSION = "3.0.0"
def initialize app, behavior
@app = app
@behavior = behavior
@after = @behavior.instance_methods.map(&:to_s).include? "after"
end
class Intercession
def initialize app, behavior
@app = app
@behavior = behavior
@before, @after = %w(before after).map { |m| @behavior.instance_methods.map(&:to_s).include? m }
end
def call env
session = env["rack.session"] and session.extend @behavior