Skip to content

Instantly share code, notes, and snippets.

View mguterl's full-sized avatar

Mike Guterl mguterl

View GitHub Profile
require 'rubygems'
require 'spec'
class MyExampleGroup < Spec::ExampleGroup
before(:each) do
puts "in before(:each)"
my_custom_method
end
class << self
@gaffneyc
gaffneyc / rpc_consumer.rb
Created June 3, 2009 15:07
Basic RPC using RabbitMQ and Bunny
require 'rubygems'
gem 'gaffneyc-bunny'
require 'bunny'
# Example of simple RPC using server named queues
Bunny.open do |amqp|
# Exchange definition
amqp.exchange('reply', :type => :direct)
amqp.exchange('out', :type => :direct)
@schorsch
schorsch / gist:134652
Created June 23, 2009 16:24
Rails Form helper to ease the rendering of nested_forms via accepts_nested_attributes_for
module KingForm
# Method for building forms that contain fields for associated models.
module NestedFormHelper
# Renders the form for nested objects defined via activerecord accepts_nested_attributes_for
#
# The associated argument can be either an object, or a collection of objects to be rendered.
#
# An options hash can be specified to override the default behaviors.
require 'sunspot'
require 'sunspot/session_proxy/abstract_session_proxy'
require 'resque'
require 'resque-retry'
class SunspotResqueSessionProxy < Sunspot::SessionProxy::AbstractSessionProxy
attr_reader :session
delegate :config, :delete_dirty?, :dirty?,
:new_search, :search,

If one was inclined to use the acts_as_yaffle pattern, they would probably use the second one, rather than the heavily cargo-culted first one.

# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
# backup redis databases to s3 on the engineyard platform
require 'zlib'
require 'rubygems'
require 'crack/json'
require 'aws/s3'
class Redis2S3
DATABASE = '/db/redis/redis_state.rdb'
#!/usr/bin/env ruby"
require 'rake/clean'
require 'rake/testtask'
task :default => :test
Rake::TestTask.new(:test) do |t|
t.warning = true
t.verbose = false
@technoweenie
technoweenie / mapper.coffee
Created August 15, 2010 08:28
Javascript => Coffeescript screencast: http://screenr.com/xd0
#
# Module dependencies
#
utils = require './utils'
#
# @api private
#
class Mapper
constructor: (phases, riak) ->
@mnutt
mnutt / Instrument Anything in Rails 3.md
Created September 6, 2010 06:50
How to use Rails 3.0's new notification system to inject custom log events

Instrument Anything in Rails 3

With Rails 3.0 released a few weeks ago I've migrated a few apps and I'm constantly finding useful new improvements. One such improvement is the ability to log anything in the same way that Rails internally logs ActiveRecord and ActionView. By default Rails 3 logs look slightly spiffier than those produced by Rails 2.3: (notice the second line has been cleaned up)

Started GET "/" for 127.0.0.1 at Mon Sep 06 01:07:11 -0400 2010
  Processing by HomeController#index as HTML
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
  CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1

Rendered layouts/_nav.html.erb (363.4ms)