This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //node()[@attribute and not(@attribute <= preceding-sibling::node()/@attribute) and not(@attribute <=following-sibling::node()/@attribute)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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##*/}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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]) |