Skip to content

Instantly share code, notes, and snippets.

@dimus
dimus / Hash.from_xml using Nokogiri
Created Mar 17, 2010
Adding Hash.from_xml method using Nokogiri
View Hash.from_xml using Nokogiri
# USAGE: Hash.from_xml:(YOUR_XML_STRING)
require 'nokogiri'
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#1231297
class Hash
class << self
def from_xml(xml_io)
begin
result = Nokogiri::XML(xml_io)
return { result.root.name.to_sym => xml_node_to_hash(result.root)}
@rkumar
rkumar / gist:445992
Created Jun 20, 2010
subcommand parser wrapping over OptionParser (ruby)
View gist:445992
#!/usr/bin/env ruby -w
######################################
# A tiny wrapper over optparse that gives easy subcommand facility.
# It also neatly prints help for global and subcommands
# as well as summarizes subcommands in global help.
#
# For updated version, goto : http://github.com/rkumar/subcommand
#
# @author Rahul Kumar, Jun 2010
# @date 2010-06-20 22:33
View api.feature
Scenario: Get List of My Hitchhiking Items via API
Given the existing things:
|name|
|The Guide (duh)|
|A towel|
|Sub-Etha Sens-O-Matic|
|Pan Galactic Gargle Blaster|
|Kill-o-Zap blaster pistol|
And the existing accounts:
|email|name|password|
View deep_cloning.rb
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
View achievements.rb
class Achievement
class << self
attr_accessor :all
end
self.all = []
attr_accessor :badge
def initialize(badge)
@badge = badge
@timblair
timblair / caveatPatchor.js
Created Feb 15, 2011 — forked from protocool/caveatPatchor.js
Sample caveatPatchor.js file for use in Propane 1.1.2 and above: pulls avatars from Gravatar
View caveatPatchor.js
/*
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 Feb 17, 2011
Playing around with a Bottom object and try operator.
View bottom_try_spec.rb
require 'rspec/given'
class Object
def _?
self
end
def _
self
end
end
View hostname.rb
#
# Cookbook Name:: cloud
# Recipe:: hostname
#
template "/etc/hosts" do
source "hostname/hosts.erb"
owner "root"
group "root"
mode 0644
@kesor
kesor / gist:1029749
Created Jun 16, 2011
RSyslog <-> ElasticSearch LogStash events
We couldn’t find that file to show.
@brentkirby
brentkirby / service
Created Jun 22, 2011
Unicorn + Runit + RVM
View service
#!/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 {