This file contains 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
# 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. | |
* |
This file contains 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
# FAIL | |
value = compute_value | |
value = (value > CONSTANT) ? value : CONSTANT | |
# WIN | |
value = [compute_value, CONSTANT].max |
This file contains 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
# 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) |
This file contains 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
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 |
This file contains 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 | |
require 'rubygems' | |
require 'thin' | |
require 'sinatra' | |
post(/.*/) do | |
`rake deploy:stage` | |
end | |
This file contains 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
$ time thor scraper:extract cbc_scraper postal_codes.txt > codes_to_edids.csv | |
real 193m57.176s | |
user 0m39.874s | |
sys 0m15.645s |
This file contains 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 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 |
This file contains 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
$ 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 | |
This file contains 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
class Euclidean | |
class << self | |
def similarity(item,other) | |
new.sim(item,other) | |
end | |
#inline(:Ruby) do |builder| | |
# builder.optimize :similarity | |
#end |
This file contains 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
# > {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 |