Skip to content

Instantly share code, notes, and snippets.

# http://svn.facebook.com/svnroot/platform/samples/packages/
# therunaround.tar.gz / core.php
/**
* Returns $arr[$idx], because php doesn't let you index into
* arrays returned from a function.
*
* a()[0] doesn't work
*
* idx(a(), 0) does.
*
# FAIL
value = compute_value
value = (value > CONSTANT) ? value : CONSTANT
# WIN
value = [compute_value, CONSTANT].max
# Script written a year ago to get SAQ wines...
#
# first, get all search pages
def url(i)
"http://www.saq.com/webapp/wcs/stores/servlet/CatalogSearchResultView?storeId=10001&langId=-2&catalogId=10001&searchTerm=&resultCatEntryType=2&beginIndex=#{i}&tri=RechercheUCIProdDescAttributeInfo&sensTri=AscOperator&searchType=400&codeReseau=&categoryId=11748&viewTaskName=SAQCatalogSearchResultView&catalogVenteId=&origineId=&codePrix=&pageSize=100"
end
(0..71).each do |i|
`curl '#{url(i*100)}' > saq/#{i*100}`
sleep(30)
class ApplicationController < ActionController::Base
def set_time_zone
if current_user
Time.zone = current_user.time_zone
logger.debug "set time zone to #{Time.zone.name}"
end
end
end
class Reports::BaseController < ApplicationController
#!/usr/bin/env ruby
require 'rubygems'
require 'thin'
require 'sinatra'
post(/.*/) do
`rake deploy:stage`
end
$ time thor scraper:extract cbc_scraper postal_codes.txt > codes_to_edids.csv
real 193m57.176s
user 0m39.874s
sys 0m15.645s
# We order a LOT of pizza at GiraffeSoft
# (there are 14 empty boxes on the table, and 3 more on the way)
# So, what's the cheapest way to buy them?
#
# in irb,
# include PizzaOptimizer
# compare([[9,11],[12,14],[14, 21]])
# 9" @ 11 => 0.270170428088094
# 12" @ 14 => 0.25788995408409
# 14" @ 21 => 0.331572798108115
$ rake stats
(in /Users/danielharan/projects/giraffesoft/SEEKRIT)
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers | 283 | 234 | 15 | 28 | 1 | 6 |
| Helpers | 185 | 108 | 0 | 13 | 0 | 6 |
| Models | 304 | 229 | 9 | 28 | 3 | 6 |
| Libraries | 263 | 147 | 1 | 30 | 30 | 2 |
| Functional tests | 857 | 689 | 17 | 10 | 0 | 66 |
class Euclidean
class << self
def similarity(item,other)
new.sim(item,other)
end
#inline(:Ruby) do |builder|
# builder.optimize :similarity
#end
# > {1 => 'a', 2 => 'b', 3 => 'a'}.values.histogram
# => {"a"=>2, "b"=>1}
class Array
def histogram
inject(Hash.new(0)) do |memo,value|
memo[value] += 1
memo
end
end
end