Skip to content

Instantly share code, notes, and snippets.

View jbarnette's full-sized avatar

John Barnette jbarnette

View GitHub Profile
@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
@bryanl
bryanl / campfire-emoji.txt
Created January 27, 2011 16:34
campfire emoji
Surround these with : e.g. :calling:
+1
-1
bulb
calling
clap
cop
email
feet
@bdotdub
bdotdub / redis.markdown
Created November 24, 2010 22:18
Running redis using upstart on Ubuntu

Running redis using upstart on Ubuntu

I've been trying to understand how to setup systems from the ground up on Ubuntu. I just installed redis onto the box and here's how I did it and some things to look out for.

To install:

(function() {
var ua = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3';
if (navigator.userAgent.indexOf(ua) === 0) {
document.write('<sc' + 'ript src="/js/ios3_bug.js"></sc' + 'ript>');
}
})();
// iPhone OS 3 requires an external script tag to be synchronously
// loaded in the HEAD od the HTML document if there's a reference
@drnic
drnic / snippet.rb
Created July 12, 2010 23:27
Sometimes you just need to know if anyone has forked your project recently
#!/usr/bin/env ruby
#
# USAGE:
#
# ruby -rubygems -ropen-uri -e 'eval open("http://gist.github.com/raw/473222/snippet.rb").read' jbarnette dr-nic-magic-awesome
#
# Or locally:
#
# $ show_forks jbarnette dr-nic-magic-awesome
# jbarnette - 2008/06/05 15:54:29 -0700
~$ ARCHFLAGS='-arch i386 -arch x86_64'
~$ rvm install 1.8.7 --debug --reconfigure -C --enable-shared=yes
~$ wget http://sourceforge.net/projects/rubycocoa/files/RubyCocoa/1.0.0/RubyCocoa-1.0.0.tar.gz/download
~$ tar xzf RubyCocoa-1.0.0.tar.gz && rm RubyCocoa-1.0.0.tar.gz && cd RubyCocoa-1.0.0
~/RubyCocoa-1.0.0$ ruby install.rb config --build-universal=yes
~/RubyCocoa-1.0.0$ ruby install.rb setup
~/RubyCocoa-1.0.0$ sudo ruby install.rb install
@shinzui
shinzui / connection_fix.rb
Created December 6, 2009 06:18 — forked from defunkt/connection_fix.rb
MySQL automatic reconnect
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/
# Run the given block +num+ times and then print out the mean, median, min,
# max, and stddev of the run. For example:
#
# irb> stats(10) { sleep(rand / 100) }
# mean: 5.99ms
# median: 6.76ms
# min: 1.49ms
# max: 9.28ms
# stddev: 2.54ms
def stats(num)