Skip to content

Instantly share code, notes, and snippets.

View subelsky's full-sized avatar
🧘‍♂️

Mike Subelsky subelsky

🧘‍♂️
View GitHub Profile
@subelsky
subelsky / twilio_goliath.rb
Created September 8, 2011 19:01
Using Goliath as an API Proxy
require 'goliath'
require 'em-synchrony/em-http'
class TwilioResponse < Goliath::API
use Goliath::Rack::Params
use Goliath::Rack::JSONP
HEADERS = { authorization: ENV.values_at("TWILIO_SID","TWILIO_AUTH_TOKEN") }
BASE_URL = "https://api.twilio.com/2010-04-01/Accounts/#{ENV['TWILIO_SID']}/AvailablePhoneNumbers/US"
@subelsky
subelsky / audio.rake
Created November 4, 2011 14:15
Rake task to prepare MP3 files for Apple's HTTP Streaming protocol and upload them to S3
namespace :audio do
desc "downsample, segment, and upload audio files"
task :load => :environment do
access_key_id = ENV['AWS_ACCESS_KEY_ID']
secret_access_key = ENV['AWS_ACCESS_KEY']
source_dir = ENV['SOURCE_DIR']
fail "Must specify AWS_ACCESS_KEY_ID, AWS_ACCESS_KEY, and SOURCE_DIR" if access_key_id.blank? || secret_access_key.blank? || source_dir.blank?
filenames = Dir["#{source_dir}/**/**.*"]
fail "#{source_dir} is empty" if filenames.empty?
@subelsky
subelsky / gist:2227323
Created March 28, 2012 15:29
Parsing surveymonkey result data
html = IO.read("survey.html")
rows = Nokogiri::HTML(html).css("tr")[????].collect { |r| r.children.to_a.values_at(0,3).collect(&:content) }.sort_by(&:last).reverse.collect { |r| "#{r.first} - #{r.last}" }
@subelsky
subelsky / move_github_repos.sh
Created April 10, 2012 16:30
How to archive old github private projects on Dropbox
# http://stackoverflow.com/questions/1960799/using-gitdropbox-together-effectively/1961515#1961515
export REPONAME=????
take ~/Dropbox/git/$REPONAME.git
git init --bare
cd ~/code/$REPONAME
git remote rm origin
git remote add origin ~/Dropbox/git/$REPONAME.git
git push -u origin master
@subelsky
subelsky / migration_generator.rb
Created April 12, 2012 17:49
Open Rails migrations in an editor automatically after creation
# As soon as I create a Rails migration I always want to open that file in an editor.
# I'd like to submit the following patch to Rails to create an --editor argument
# for the migration generator but I can't quite figure out the Thor way of doing this.
require 'rails/generators/active_record'
module ActiveRecord
module Generators
class MigrationGenerator < Base
argument :editor, :type => :string, :lazy_default => ENV['EDITOR'], :required => false, :banner => "/path/to/your/editor", :desc => "Open migration using specified editor (defaults to EDITOR)"
@subelsky
subelsky / fetcher.rb
Created May 3, 2012 13:29
Apprentice Homework Assignment
# Two of the projects we'll be discussing are heavily dependent on code like the example below, which
# requests stock price information from Google's finance API and transforms the results into a hash
# for use in our database. This pattern shows up over and over in my projects. I always setup a separate
# codebase containing a bunch of worker" modules that just do stuff like this.
#
# I need to write a bunch more of these for a variety of data sources. My plan is to start you off
# on these, then graduate to more complex features.
#
# Here are two things for you to try:
#
@subelsky
subelsky / massive_update.sh
Created May 25, 2012 12:03
A thing I couldn't do w/o good test coverage
# I run this command once a week on all of my active projects
# It helps ensure that I'm always able to use the latest/greatest
# versions of various dependencies, or at least that I find out
# quickly when I've become locked into a particular version
# (which just happened with the latest versions of the Ruby gems
# Webmock and VCR
alias mrupd='git pull && bundle update && rdbm && rspec spec; sd'
# the alias stands for 'massive rails update' because I have a bunch of other aliases that
@subelsky
subelsky / rsh_topics_6-9-12.rb
Created June 9, 2012 16:52
Ruby Study Hall outline 6/9/12
# BEGINNER: how to get started with ruby
# http://www.rubystudyhall.com/getting_started_with_ruby
# http://tryruby.org
# irb
# run "Hello, World" from command line
# do simple calculations
# read a file and count the lines in it
# read a file from command line argument
@subelsky
subelsky / rspec_shared_controller_spec_example.rb
Created July 3, 2012 17:33
RSpec shared example tests for controllers
# how to use https://github.com/subelsky/subelsky_power_tools/blob/master/lib/subelsky_power_tools/controller_shared_behavior.rb
describe PlatformsController do
it_should_behave_like "a protected plural controller" do
let(:user) { create(:user) }
let(:object_not_owned_by_user) { create(:platform) }
let(:valid_change_params) { { platform: { username: "HEYWOOD" } } }
let(:user_sign_in_proc) { lambda { sign_in user } }
let(:signin_redirect) { new_user_session_url(protocol: "http") }
let(:not_found_redirect) { root_url }
@subelsky
subelsky / casperjs_example.js
Created August 8, 2012 18:51
Webscraping with CasperJS, PhantomJS, jQuery, and XPath
var system = require('system');
if (system.args.length < 5) {
console.info("You need to pass in account name, username, password, and path to casperJS as arguments to this code.");
phantom.exit();
}
var account = system.args[1];
var username = system.args[2];
var password = system.args[3];