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
# Example use: | |
# weigh_by_relative_importance(@report.items, :cell_value, [2,4,6,8,10]) do |item,weight| | |
# xml.movie :lat => item.latitude, :long => item.longitude, :title => item.city, | |
# :height => weight, :width => weight | |
# end | |
# Code inspired by http://www.juixe.com/techknow/index.php/2006/07/15/acts-as-taggable-tag-cloud/ | |
# and meant to be usable for items on a map (as above) or tags | |
module MapHelper | |
def weigh_by_relative_importance(items, method_name, classes) | |
sorted = items.collect {|item| item.send(method_name)}.sort |
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 Jaccard | |
def self.coefficient(a,b) | |
result = (a & b).length / (a + b).uniq.length.to_f | |
(result * 1000).round / 1000.0 | |
end | |
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 |
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
$ 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
# 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
$ 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
#!/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
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
# 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) |