Skip to content

Instantly share code, notes, and snippets.

@outoftime
outoftime / criteria.rb
Created January 21, 2011 22:07
Instantiate the results of map-reduce operations as Mongoid documents
module Mongoid
class Criteria
include Criterion::MapReduce
end
end
@tekacs
tekacs / show
Created April 20, 2011 17:55
This does something essentially equivalent to showoff.io if you have a publicly facing server...
# Usage: show <local-port> <subdomain>
function show() {
DOMAIN=".tekacs.com"
REMOTE="$2$DOMAIN"
ssh -tR 1080:127.0.0.1:$1 vps "sudo ssh -Nl \$USER -L $REMOTE:80:127.0.0.1:1080 localhost"
}
@oisin
oisin / gist:987247
Created May 23, 2011 18:34 — forked from leereilly/gist:987094
API version checking using Sinatra's before filter; supports nested resources
require 'sinatra'
# Set the version of the API being run here
#
MAJOR_VERSION = 1
MINOR_VERSION = 0
VERSION_REGEX = %r{/api/v(\d)\.(\d)}
helpers do
def version_compatible?(nums)
@etrepat
etrepat / criteria.rb
Created June 12, 2011 18:56 — forked from outoftime/criteria.rb
Instantiate the results of map-reduce operations as Mongoid documents
module Mongoid
class Criteria
include Criterion::MapReduce
end
end
@justinko
justinko / callback_disabler.rb
Created September 2, 2011 00:20
Disable raw filter callbacks in RSpec
# In spec/support/callback_disabler.rb
module CallbackDisabler
def self.store_callbacks(model, filters)
model = constantize(model)
filters.each do |filter|
model.send("_#{filter}_callbacks").each do |callback|
stored_callbacks[model] << {
filter: filter, kind: callback.kind, raw_filter: callback.raw_filter
}
@shreyas-satish
shreyas-satish / show
Created September 5, 2011 06:42 — forked from tekacs/show
This does something essentially equivalent to showoff.io if you have a publicly facing server...
# Usage: show <local-port> <subdomain>
function show() {
DOMAIN=".tekacs.com"
REMOTE="$2$DOMAIN"
ssh -tR 1080:127.0.0.1:$1 vps "sudo ssh -Nl \$USER -L $REMOTE:80:127.0.0.1:1080 localhost"
}
@stevecj
stevecj / enhanced_attributable.rb
Last active September 30, 2015 20:47
Ruby attr_accessor enhancement
# Include this module in a class to add enhanced attr_accessor
# functionality. With this module included, ...
#
# * You may provide a block to an attr_accessor call that accepts
# a base attribute name and returns a default value for each
# instance attribute.
# * Any attribute name consisting of a base name followed by a
# "?" suffix represents a boolean attribute.
#
# If the including class has its own #initialize method, that
@justinko
justinko / seed.rb
Created February 27, 2012 01:24
FactoryGirl for dev seeding and tests
# lib/tasks/app.rake
namespace :app do
desc 'Seed the current env db with "dummy" data'
task seed: :environment do
require './lib/seed'
Seed.start
end
end
@kdisneur
kdisneur / gist:2337544
Created April 8, 2012 14:19
improve ordinal_array speed
require './lib/ordinal_array'
require "benchmark"
number_values = (0...999).sort_by{rand}
number_letters = [
:first, :second, :third, :fourth, :fifth, :sixth, :seventh, :eighth, :ninth,
:tenth, :eleventh, :twelfth, :thirteenth, :fourteenth, :fifteenth, :sixteenth, :seventeenth, :eighteenth, :nineteenth,
:twentieth, :twenty_first, :twenty_second, :twenty_third, :twenty_fourth, :twenty_fifth, :twenty_sixth, :twenty_seventh, :twenty_eighth, :twenty_ninth,
:thirtieth, :thirty_first, :thirty_second, :thirty_third, :thirty_fourth, :thirty_fifth, :thirty_sixth, :thirty_seventh, :thirty_eighth, :thirty_ninth,
:fortieth, :fourty_first, :fourty_second, :fourty_third, :fourty_fourth, :fourty_fifth, :fourty_sixth, :fourty_seventh, :fourty_eighth, :fourty_ninth,
@2bits
2bits / wkhtmltopdf.rb
Created April 14, 2012 10:53
wkhtmltopdf-0.11.0_rc1 hack to build their patched qt as an option
require 'formula'
class WkhtmltopdfQt < Formula
url 'git://gitorious.org/+wkhtml2pdf/qt/wkhtmltopdf-qt.git'
end
class Wkhtmltopdf < Formula
homepage 'http://code.google.com/p/wkhtmltopdf/'
url 'http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.11.0_rc1.tar.bz2'
sha1 'db03922d281856e503b3d562614e3936285728c7'