Skip to content

Instantly share code, notes, and snippets.

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

Mike Subelsky subelsky

🧘‍♂️
View GitHub Profile
@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 / 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 / Gemfile
Created July 28, 2011 14:17
Getting SSL, Capybara, Rails 3, and Devise to work together
gem "rack-ssl", "1.3.2"
# when Capybara issue 409 or 422 get resolved, you can switch back to the official
# capybara gem
# https://github.com/jnicklas/capybara/pull/409
# https://github.com/jnicklas/capybara/pull/422
gem "capybara", git: "https://github.com/mcolyer/capybara.git", branch: "fix-ssl-redirects"
@subelsky
subelsky / null_zero_obj.rb
Created July 1, 2011 20:51
using a null zero object
# I have a function that looks up a monthly report which may or may not exist yet (e.g. if
# you look at the start of a month, before I've gotten around to generating that month's
# report)
#
# where the report isn't generated I just want to return "0" for each column in this report;
# so what I do is return an instance of the below object whenever there's no report
# available (thus avoiding any "try" unpleasantness) - something about this slightly
# bothers me though. Is there a more elegant/simpler way I should consider?
class NullZeroObject
@subelsky
subelsky / gist:878603
Created March 20, 2011 19:39
Possible memory leak in therubyracer
require "rubygems"
require "v8"
require "ostruct"
require "memprof"
funcs = []
3.times do
cxt = V8::Context.new
funcs << cxt.eval("f = function(arg) { return arg.a + arg.b }")
@subelsky
subelsky / macvim command key mapping
Created January 18, 2011 01:10
maps the apple key plus a number to change tabs in Macvim, just like any other app
map <D-1> 1gt
map <D-2> 2gt
map <D-3> 3gt
map <D-4> 4gt
map <D-5> 5gt
map <D-6> 6gt
map <D-7> 7gt
map <D-8> 8gt
map <D-9> 9gt
class Tracker
def track_event(a,b,c)
@queue ||= Queue.new
start_pushing_thread
hash = { :a => a, :b =>, :c => c }
@queue << hash
end
private
# modified from http://www.mikeperham.com/2009/03/03/using-memcache-client-16x-in-rails-23
# Brain surgery to use our own version of memcache-client without having to modify activesupport directly.
# Unload any previous instance of the class
if Object.const_defined? :MemCache
Object.instance_eval { remove_const :MemCache }
end
# Ensure that the memcache-client gem path is at the front of the loadpath
$LOAD_PATH.unshift(RAILS_ROOT + '/vendor/gems/memcache-client-1.7.4/lib')
begin
# check if memcached is running; if it is, use that instead of the default memory cache
Timeout.timeout(0.5) { TCPSocket.open("localhost", 11211) { } }
config.cache_store = :mem_cache_store, %w(localhost:11211), { :namespace => 'OI', :timeout => 60 }
$stderr.puts "Using memcached on localhost:11211"
rescue StandardError
config.cache_store = nil
$stderr.puts "memcached not running, caching to memory"
end
export GIT_EDITOR="mate -w"
export LESS="-erX" # makes git diff look nicer
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
export PS1='\h \[\033[1;33m\]\w\[\033[0m\]$(parse_git_branch)$ '