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.
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
| # | |
| # 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 | |
| # |
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
| # 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: |
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
| #!/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 |
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
| # 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 |
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
| 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'. |
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 'isolate' | |
| Isolate.now! do | |
| gem 'sinatra' | |
| end | |
| require 'sinatra' | |
| $x = 0 | |
| $procs = {} |
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
| 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 |
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
| 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. |
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
| # 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}\":" |