This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test/unit' | |
require 'rubygems' | |
require 'activesupport' | |
require 'shoulda/test_unit' | |
module ShouldaExtensions | |
def self.included(klass) | |
klass.class_eval do | |
include FixmeMethods |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A shoulda macro for verifying a class has the writer attribute readers, | |
# writers and accessors. NOTE: I could be silly for wanting this. But it was | |
# there. So here it is. | |
# | |
# (c) Copyright 2009 Adam Keys. MIT license. | |
module AccessorMacros | |
def should_have_reader(name) | |
should "have an attribute reader for #{name.to_s}" do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module BlameTheCompiler | |
def method_added(name) | |
if rand(3) != 1 | |
undef_method(name) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'validatable' | |
module ValidatableForm | |
module ClassMethods | |
def fields | |
@fields ||= [] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# attribute_mapper is a plugin I worked on a little at FiveRuns | |
# and later extracted because I think it's rad. It's a better way to do | |
# enumerated values in your models. | |
# | |
# I'm giving it a little love this week. One of the things I'd like to do is | |
# make it a little cleaner vis a vis contemporary Ruby coding practice. One | |
# of the changes I'd like to make is to switch to explicitly including | |
# attribute_mapper in models that use it, rather than having it inject itself | |
# into every model in your app. | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def map_e(elz, &block) | |
results = [] | |
if length > 0 | |
each do |o| | |
block.call(o) | |
end | |
else | |
elz.call | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source :rubygems | |
gem 'sinatra', '1.0' | |
gem 'oauth2' | |
gem 'json' | |
group :development do | |
gem 'shotgun' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class QueryTracer < ActiveSupport::LogSubscriber | |
ACCEPT = %r{^(app|config|lib)}.freeze | |
FRAMES = 5 | |
THRESHOLD = 300 # In ms | |
def sql(event) | |
return unless event.duration > THRESHOLD | |
callers = Rails. | |
backtrace_cleaner. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cassandredis.rb - It makes your Cassandra look like a Redis. | |
require "cassandra/0.7" | |
class Cassandredis | |
# Connect to a keyspace and column family. | |
def initialize(keyspace, cf) | |
@client = Cassandra.new(keyspace) | |
@cf = cf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Append-only sets | |
# | |
# Dustin Sallings described [how to implement sets in memcached using only | |
# atomic commands](http://dustin.github.com/2011/02/17/memcached-set.html). | |
# This implements the necessary encoding/decoding for that | |
# scheme. You could then use this with a database that doesn't support sets. | |
# | |
# N.B. This is a naive implementation (see the pending specs), but it's fun. | |
# An append-only set is, after all, a set |