Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'sinatra/base'
class Foo < Sinatra::Base
condition { params[:bar] == '1' }
get('/foo') do
"i'm in bar == 1!"
end
get('/foo') do
Person 1: Do you run your tests on the same DB or do you use like sqlite3 instead?
Person 2: Person 1, it's almost always advisable to run tests on the same db as prod (and dev too)
Person 1: Was that sarcasm?
Person 2: no
namespace :resque do
desc "Process exactly one job and quit"
task :work_one => :setup do
require 'resque'
worker = nil
queues = (ENV['QUEUES'] || ENV['QUEUE']).to_s.split(',')
begin
worker = Resque::Worker.new(*queues)
@ryanbriones
ryanbriones / gist:270075
Created January 6, 2010 06:18
Script to alert campfire of Pivotal Tracker activity
require 'rubygems'
require 'httparty'
require 'json'
require 'dm-core'
class MyProjectTracker
include HTTParty
base_uri 'https://www.pivotaltracker.com/services/v2/projects/YOUR_PROJECT_ID'
headers 'X-TrackerToken' => 'YOUR_API_KEY'
@ryanbriones
ryanbriones / gist:269803
Created January 5, 2010 22:27 — forked from madmimi/gist:269783
post to Campfire via new API
require 'httparty'
require 'json'
class Campfire
include HTTParty
base_uri 'https://YOUR_DOMAIN.campfirenow.com'
basic_auth 'YOUR_API_KEY', 'X' # yes, that is a literal X string. it's needed to satisfy basic_auth(), but campfire ignores it.
headers 'Content-Type' => 'application/json'
def self.speak(message)
# getting more power out of Enumerable
# this is to convert an RGB data structure, into RGBA
RGB_WIDTH = 3
raw_data = [1,1,1,2,2,2,3,3,3,4,4,4]
# returns an enumerable object with the raw data split up into chunks of 3
pixels = raw_data.enum_slice( RGB_WIDTH )
@ryanbriones
ryanbriones / gist:266619
Created December 31, 2009 04:53
find node with the maximum value of a specific attribute
//node()[@attribute and not(@attribute <= preceding-sibling::node()/@attribute) and not(@attribute <=following-sibling::node()/@attribute)]
if [ "$1" ]; then
BRANCH=$1
else
BRANCH=$(git branch | grep '*' | cut -d ' ' -f2)
fi
REMOTE=$(git config --get branch.$BRANCH.remote)
REMOTE_BRANCH=$(git config --get branch.$BRANCH.merge)
echo "$REMOTE/${REMOTE_BRANCH##*/}"
@ryanbriones
ryanbriones / gist:251748
Created December 8, 2009 15:57
ahh, my first night in chicago after my iPhone, my only alarm clock, broke. good times.
require 'time'
loop do
if Time.now > Time.parse('06:30')
`/usr/bin/open "/Users/ryanbriones/Music/iTunes/iTunes Music/Daft Punk/Discovery/01 One More Time.mp3"`
break
end
puts "#{Time.now} not #{Time.parse('06:30')}"
sleep 5
@ryanbriones
ryanbriones / gist:246599
Created December 1, 2009 20:17
send email to gmail (STARTTLS) using ruby >=1.8.7
# send email using STARTTLS; Net::SMTP#enable_starttls requires ruby >=1.8.7
# this hack is needed for rails <2.3; apparently >=2.3 has something for this already
ActionMailer::Base.class_eval do
private
def perform_delivery_smtp(mail)
destinations = mail.destinations
mail.ready_to_send
smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port])