Skip to content

Instantly share code, notes, and snippets.

View danryan's full-sized avatar
🔥

Dan Ryan danryan

🔥
View GitHub Profile
# Video: http://rubyhoedown2008.confreaks.com/08-chris-wanstrath-keynote.html
Hi everyone, I'm Chris Wanstrath.
When Jeremy asked me to come talk, I said yes. Hell yes. Immediately. But
then I took a few moments and thought, Wait, why? Why me? What am I supposed
to say that's interesting? Something about Ruby, perhaps. Maybe the
future of it. The future of something, at least. That sounds
keynote-y.
@dimus
dimus / Hash.from_xml using Nokogiri
Created March 17, 2010 14:29
Adding Hash.from_xml method 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 June 20, 2010 18:20
subcommand parser wrapping over OptionParser (ruby)
#!/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
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|
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
@lukaszkorecki
lukaszkorecki / autotest-growl.markdown
Created September 28, 2010 09:41
autotest-growl icon set

World famous FFFFFFFFUUUUUUUUU autotest-growl icon set

fucons

  1. download
  2. Edit your .autotest and add this line: Autotest::Growl::image_dir = File.expand_path("~")+'/Dropbox/Public/fu' (or wherever you unpacked fu.zip)
  3. ???????
  4. Profit!
@ryansch
ryansch / hooks_controller.rb
Created September 28, 2010 15:03
Rails Controller for Chargify Webhooks
require 'md5'
class Chargify::HooksController < ApplicationController
protect_from_forgery :except => :dispatch
before_filter :verify, :only => :dispatch
EVENTS = %w[ test signup_success signup_failure renewal_success renewal_failure payment_success payment_failure billing_date_change subscription_state_change subscription_product_change ].freeze
def dispatch
event = params[:event]
class Achievement
class << self
attr_accessor :all
end
self.all = []
attr_accessor :badge
def initialize(badge)
@badge = badge
@joeyAghion
joeyAghion / simple_redis_profile.rb
Created October 13, 2010 16:00
By sampling keys from your redis databases, this script tries to identify what types of keys are occupying the most memory.
#!/usr/bin/env ruby
# Evaluates a sample of keys/values from each redis database, computing statistics for each key pattern:
# keys: number of keys matching the given pattern
# size: approximation of the associated memory occupied (based on size/length of value)
# percent: the proportion of this 'size' relative to the sample's total
#
# Copyright Weplay, Inc. 2010. Available for use under the MIT license.
@juliocesar
juliocesar / testing_front_end_rspec_capybara.md
Created October 21, 2010 23:51
Testing front-end for a Sinatra app with RSpec and Capybara

Testing front-end for a Sinatra app with RSpec and Capybara

I've used Cucumber quite a bit on my last job. It's an excellent tool, and I believe readable tests are the way to the future. But I could never get around to write effective scenarios, or maintain the boatload of text that the suite becomes once you get to a point where you have decent coverage. On top of that, it didn't seem to take much for the suite to become really slow as tests were added.

A while ago I've seen a gist by Lachie Cox where he shows how to use RSpec and Capybara to do front-end tests. That sounded perfect for me. I love RSpec, I can write my own matchers when I need them with little code, and it reads damn nicely.

So for my Rails Rumble 2010 project, as usual, I rolled a Sinatra app and figured I should give the idea a shot. Below are my findings.

Gemfile