Skip to content

Instantly share code, notes, and snippets.

View dm_factory_girl.rb
require 'test/unit'
require 'rubygems'
require 'shoulda'
require 'factory_girl'
require 'dm-core'
require 'dm-validations' # Needed for save!
class User
rtomayko / Tests Is Wrong
Created Jan 28, 2009
Why "require 'rubygems'" In Your Library/App/Tests Is Wrong
View Tests Is Wrong
In response to all the responses to:
You should never do this in a source file included with your library,
app, or tests:
require 'rubygems'
The system I use to manage my $LOAD_PATH is not your library/app/tests
jnunemaker / authentication.rb
Created Jul 15, 2009
a starting point for authentication with mongomapper and rails
View authentication.rb
# include this in application controller
module Authentication
# Inclusion hook to make #current_user and #signed_in?
# available as ActionView helper methods.
def self.included(base)
base.send :helper_method, :current_user, :signed_in?, :authorized? if base.respond_to? :helper_method
# Returns true or false if the user is signed in.
actsasflinn / kyoto_cabinet_099_snow_leopard_compatibility.patch
Created Apr 2, 2010
Kyoto Cabinet patch fix compatibility on Mac OSX Snow Leopard (Kyoto Cabinet 0.9.9)
View kyoto_cabinet_099_snow_leopard_compatibility.patch
--- 2010-04-01 22:59:17.000000000 -0400
+++ 2010-04-01 23:04:41.000000000 -0400
@@ -178,12 +178,12 @@ Mutex::Mutex(Type type) {
- if (::pthread_mutexattr_settype(&attr, ::PTHREAD_MUTEX_ERRORCHECK) != 0)
+ if (::pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK) != 0)
throw std::runtime_error("pthread_mutexattr_settype");
View mixin_models.rb
module Food
def self.included(model) :id, Serial :price, Integer, :min => 0 # builtin validation works just fine :calories, Integer, :min => 0
model.before(:valid?, :custom_validation)
def custom_validation
View sinatra_patch.rb
module Sinatra
class Base
def call!(env)
@env = env
@request =
@response =
@params = indifferent_params(@request.params)
igrigorik / webapp.rb
Created Nov 13, 2010
Inspired by @JEG2's talk at Rubyconf... Any ruby object, as a webapp! 'Cause we can. :-)
View webapp.rb
require 'rubygems'
require 'rack'
class Object
def webapp
class << self
define_method :call do |env|
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
[200, {}, send(func, *attrs)]
BinaryMuse / moodle.js
Created Nov 19, 2010
FireSheep handler for Moodle
View moodle.js
name: '',
url: '',
icon: '',
domains: [ '' ],
sessionCookieNames: [ 'MoodleSession', 'MoodleSessionTest' ],
identifyUser: function() {
var site = this.httpGet('');
this.userName = site.body.querySelector('div.logininfo a').text;
# To just pull changes from Github, forcing Git to use your local changes for any conflicts:
git pull --strategy=ours origin master
# To completely update each of your Git repositories in one command (run this inside each repository):
git add . && git commit -m "Updating to current working version" && git pull --strategy=ours origin master && git push origin master