Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'curb'
client = Curl::Easy.new('http://bit.ly/fleakr') do |config|
config.follow_location = true
config.max_redirects = 5
end
client.http_head
require 'snip_snap'
require 'hpricot'
module Rack
# = Rack::Snapshot
#
# Takes the image tags in your page and expands them using some of the popular
# image sharing services. Currently supports these services:
#
@reagent
reagent / env.rb
Created March 1, 2010 16:14
Simple Cuke stuff
require 'rubygems'
require 'cucumber'
require 'capybara'
require 'capybara/cucumber'
require 'capybara/session'
Before do
Capybara.current_driver = :selenium
module Validatable
def save
false
end
def save!
false
end
#!/bin/bash
branch=`git status | head -n1 | cut -d' ' -f4`
rake cruise && git checkout master && git merge $branch && rake cruise && git push
@reagent
reagent / etsy_verification_app.rb
Created November 7, 2010 02:26
A simple Sinatra app to test the OAuth callback functionality in Etsy. To use: 1. Install dependencies 2. Supply a valid api key & secret 3. Run `ruby etsy_verification_app.rb` 4. Point a browser to http://localhost:4567/
require 'rubygems'
require 'sinatra'
require 'etsy'
enable :sessions
Etsy.access_mode = :read_write
Etsy.api_key = "key"
Etsy.api_secret = "secret"
Etsy.callback_url = "http://localhost:4567/verify"
@reagent
reagent / inspect.js
Created January 21, 2011 04:13
Inspect JavaScript objects -- useful for debugging.
var Inspector = function(target) {
var inspector = this,
target = target;
function padding(indentationLevel) {
paddingText = '';
for (var i = 0; i < indentationLevel; i++) {
paddingText += ' ';
}
#!/bin/bash
open "/Applications/Google Chrome.app" --args \
-user-agent="Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3"
@reagent
reagent / credential.rb
Created September 28, 2011 19:01
Sample code from my Using OO to Manage Control Flow post
class Credential
include ActiveModel::Validations
attr_accessor :screen_name, :oauth_token, :oauth_secret, :token, :description
validates_presence_of :screen_name, :oauth_token, :oauth_secret, :message => 'required'
validate :user_exists, :unless => :errors?
def initialize(attributes = {})
attributes.each {|k, v| set_recognized_attribute(k, v) }
@reagent
reagent / 01_unfactored.rb
Created November 3, 2011 21:17
Alternate ways of implementing lifecyle hooks that don't involve observers
class Activity < ActiveRecord::Base
# columns:
# * entity_id
# * entity_type
# * action
# * created_at
belongs_to :entity, :polymorphic => true
end