Skip to content

Instantly share code, notes, and snippets.

😄

Dan Ryan danryan

😄
Block or report user

Report or block danryan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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
@octplane
octplane / mongo_pubsub.rb
Created Nov 9, 2010
Simple Pub/Sub system using MongoDB, capped collections and tailable cursors in ruby
View mongo_pubsub.rb
require 'rubygems'
require 'mongo'
module MongoPubSub
QUEUES_COLLECTION = 'queues'
class EndSubscriptionException < Exception; end
class Publisher
def initialize(queue_name, mongo_connection)
# Initialize queue collection as a capped collection
if not mongo_connection[QUEUES_COLLECTION].collection_names.include?(queue_name)
@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.
You can’t perform that action at this time.