Skip to content

Instantly share code, notes, and snippets.

View danryan's full-sized avatar
🔥

Dan Ryan danryan

🔥
View GitHub Profile
module Mongoid
module DeepCloning
def deep_clone(attrs = {}, obj = nil)
returning obj || self.class.new do |o|
o.write_attributes(@attributes.merge(attrs).except("_id", "versions").except(*o.class.associations.keys))
yield o if block_given?
o.save
@attributes.each_pair do |key, value|
next unless proxy = self.associations[key]
case proxy.association
class Achievement
class << self
attr_accessor :all
end
self.all = []
attr_accessor :badge
def initialize(badge)
@badge = badge
@timblair
timblair / caveatPatchor.js
Created February 15, 2011 10:27 — forked from protocool/caveatPatchor.js
Sample caveatPatchor.js file for use in Propane 1.1.2 and above: pulls avatars from Gravatar
/*
As of version 1.1.2, Propane will load and execute the contents of
~Library/Application Support/Propane/unsupported/caveatPatchor.js
immediately following the execution of its own enhancer.js file.
You can use this mechanism to add your own customizations to Campfire
in Propane.
Below you'll find two customization examples.
@jimweirich
jimweirich / bottom_try_spec.rb
Created February 17, 2011 15:47
Playing around with a Bottom object and try operator.
require 'rspec/given'
class Object
def _?
self
end
def _
self
end
end
#
# Cookbook Name:: cloud
# Recipe:: hostname
#
template "/etc/hosts" do
source "hostname/hosts.erb"
owner "root"
group "root"
mode 0644
@kesor
kesor / gist:1029749
Created June 16, 2011 17:27
RSyslog <-> ElasticSearch LogStash events
We couldn’t find that file to show.
@brentkirby
brentkirby / service
Created June 22, 2011 08:50
Unicorn + Runit + RVM
#!/bin/bash -e
#
# Since unicorn creates a new pid on restart/reload, it needs a little extra love to
# manage with runit. Instead of managing unicorn directly, we simply trap signal calls
# to the service and redirect them to unicorn directly.
#
# To make this work properly with RVM, you should create a wrapper for the app's gemset unicorn.
#
function is_unicorn_alive {
@seeingidog
seeingidog / gist:1067821
Created July 6, 2011 17:34
redis ORMs/mongo ORM benchmarks
require 'benchmark'
require 'ohm'
require 'datamapper'
require 'dm-redis-adapter'
require "redis"
require 'json'
require 'mongo_mapper'
MongoMapper.connection = Mongo::Connection.new
@joshed-io
joshed-io / example_group.rb
Created July 14, 2011 01:16
Easiest possible RSpec Performance Test w/ Scenarios
# here's a quick recipe to run a performance test
# with this method, you can:
#-> easily choose the examples you want included from your existing specs
#-> define the target number of total iterations you'd like, no limit
#-> tune the transaction mix by specifying frequency metadata for each example
#-> be happy that the transaction mix is fairly homogeneous over the test interval
# (ideally you'd run this with acceptance (webrat/capybara) specs, but you
# could employ this technique for any rspec test)
#include <stdio.h>
#include <sys/mman.h>
#include <assert.h>
#include <stdlib.h>
#include <errno.h>
#include <signal.h>
#include <unistd.h>
static volatile int done = 0;