Skip to content

Instantly share code, notes, and snippets.

@panthomakos
panthomakos / group.rb
Created September 20, 2011 22:57
Custom Error Messages in Ruby
class Group
module Error
class Standard < StandardError; end
class AlreadyAMember < Standard
def message
"You are already a member of this group."
end
end
@panthomakos
panthomakos / dynamic.1.8.7.rb
Created September 20, 2011 21:50
Dynamic Exception Rescue in Ruby
#!/usr/bin/env ruby
def match_message(regexp)
m = Module.new
(class << m; self; end).instance_eval do
define_method(:===) do |error|
regexp === error.message
end
end
m
@panthomakos
panthomakos / example1.js
Created June 30, 2011 07:23
Avoiding Nested Callbacks in Javascript
var fs = require('fs');
fs.mkdir('./hello',0777,makeDirectory);
function makeDirectory(err){
if (err) throw err;
fs.writeFile('./hello/world.txt', 'Hello!', writeFile);
}
function writeFile(err){
@panthomakos
panthomakos / Gemfile
Created May 18, 2011 18:41
Spork, RSpec, Sham and Caching Classes
source 'http://rubygems.org'
gem 'rails', '3.0.4'
group :test do
gem 'database_cleaner'
gem 'rspec-rails'
gem 'rspec-rails-matchers'
gem 'sham'
gem 'spork', '=0.9.0.rc7'