Skip to content

Instantly share code, notes, and snippets.

@jamie
jamie / current.rb
Created August 7, 2008 14:55 — forked from ivey/current.rb
refactor iteration to use map
def following_pages
twitter_user.friends_count.to_i / 100 + 1
end
def following
@following ||= (1..following_pages).map do |i|
twitter.friends_for(uid, :page => i, :lite => true)
end.flatten
end
def star_sign
# 1980 is a leap year, so we're safe for Feb 29 people
# date ranges are according to wikipedia
case Date.new(1980, birthday.month, birthday.day)
when Date.new(1980, 1, 21)..Date.new(1980, 2, 18): "Aquarius"
when Date.new(1980, 2, 19)..Date.new(1980, 3, 20): "Pisces"
when Date.new(1980, 3, 21)..Date.new(1980, 4, 20): "Aries"
when Date.new(1980, 4, 21)..Date.new(1980, 5, 21): "Taurus"
when Date.new(1980, 5, 22)..Date.new(1980, 6, 21): "Gemini"
when Date.new(1980, 6, 22)..Date.new(1980, 7, 22): "Cancer"
#
# 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
#

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
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
require 'fileutils'
require 'sqlite3'
require 'uri'
require 'net/http'
require 'set'
require 'thread'
chrome_history_location = "#{ENV['HOME']}/Library/Application\ Support/Google/Chrome/Default/History"
temp_location = "/tmp/Chrome_history"
FileUtils.cp(chrome_history_location, temp_location)