Skip to content

Instantly share code, notes, and snippets.

#
# Created by Eric Lindvall <eric@sevenscale.com>
#
# WHAT: Provides a simple overview of memory allocation occuring during a
# require.
#
# For a longer explanation, see my post at:
#
# http://bitmonkey.net/post/308322913/tracking-initial-memory-usage-by-file-in-ruby
#
# We've been storing some JSON in a string field in our database,
# and needed to extract it to get something resembling reasonable
# performance on queries.
#
# Building a manual query of either INSERT INTO () SELECT or
# UPDATE forms, use it like:
#
# SELECT #{json('login')}
#
# If you have integer fields that are sometimes null or not present:
@jamie
jamie / git-track
Created March 15, 2010 18:24
git helper to track remote branches for existing local branch
#!/usr/bin/env ruby
# Sets up remote tracking if you forgot to --track a branch,
# or if you're setting up a new branch.
# Save in ~/bin/ or somewhere else on your path.
# Usage:
# git track [[remote] branch]
# remote defaults to 'origin'
# branch defaults to the name of the current local branch

If one was inclined to use the acts_as_yaffle pattern, they would probably use the second one, rather than the heavily cargo-culted first one.

@jamie
jamie / sinatra_reloader.rb
Created June 24, 2010 15:19 — forked from nutrun/sinatra_reloader.rb
sinatra-reloader standalone
# For "Classic" style/top-level type of apps do something like:
#
# configure :development do
# require File.join(File.dirname(__FILE__), 'sinatra_reloader')
# set :reload_paths, [File.join(File.dirname(__FILE__), '**', '*.rb')]
# end
#
# For "Modular" style/Sinatra::Base subclasses:
#
# configure :development do
@jamie
jamie / gist:589836
Created September 21, 2010 15:17
errors installing mkvtoolnix under fish
jamie@papa ~> brew install mkvtoolnix
==> Downloading http://www.bunkus.org/videotools/mkvtoolnix/sources/mkvtoolnix-4.3.0.tar.bz2
File already downloaded and cached to /Volumes/Users/jamie/Library/Caches/Homebrew
==> ./configure --disable-debug --prefix=/usr/local/Cellar/mkvtoolnix/4.3.0 --with-boost-libdir=/usr/local/lib --with-boost-regex=boost_regex-mt
==> ./drake -j8
==> ./drake install
./rake.d/helpers.rb:84: warning: default `to_a' will be obsolete
(in /private/tmp/homebrew-mkvtoolnix-4.3.0-55Uz/mkvtoolnix-4.3.0)
/usr/local/bin/fish ./mkinstalldirs /usr/local/Cellar/mkvtoolnix/4.3.0/bin
fish: The '$' begins a variable name. It was given at the end of an argument. Variable names may not be zero characters long. To learn more about variable expansion in fish, type 'help expand-variable'.
@jamie
jamie / foo.rb
Created February 18, 2011 02:03
require 'rubygems'
require 'isolate'
Isolate.now! do
gem 'sinatra'
end
require 'sinatra'
$x = 0
$procs = {}
def total_price
tp = Money.new(0.0, appropriate_package.base_price_currency)
puts "tp = #{tp.currency} #{tp.inspect}"
addon_packages.each do |pkg|
puts "pkg.base_price = #{pkg.base_price.currency} #{pkg.base_price}"
tax = pkg.tax_price(state_or_province).exchange_to(appropriate_package.base_price_currency)
puts "pkg.tax_price(state_or_province) = #{tax.currency} #{tax}"
tp += pkg.base_price.exchange_to(appropriate_package.base_price_currency) + tax
puts "tp = #{tp.currency} #{tp.inspect}"
end
@jamie
jamie / README
Created March 22, 2011 18:05
Get around vimeo's stupid daily download limit restrictions
Usage:
./vimeo.rb video-id [password] [output filename, no extension]
Known issues:
I should put some better arg handling in, if you download a video w/ password it will use the password as output filename.
@jamie
jamie / json_migration.rb
Created October 17, 2011 21:02
I am insane. [JSON parsing in SQL]
# TODO: self, blog this.
# NUTSHELL: Have a database column with some JSON in it that you'd maybe like to pull out and index on?
# Here's your solution. The generated sql looks pretty gnarly but mysql ran through it stupidly fast.
# I shudder to think how long it'd take activerecord to load and update each record individually.
# USAGE: In a migration.
def json(key, field='params')
key_json = "\"#{key}\":"