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
| 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 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
| # 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 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 'mechanize' | |
| postal_codes = File.open("postal_codes.txt").read.split("\n") | |
| # randomize to make the pattern slightly harder to see in logs | |
| postal_codes = postal_codes.sort_by {|e| rand(10_000)} | |
| def filename(postcode) | |
| postcode.sub(' ', '') | |
| 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
| class KeyValuePairs | |
| # Take a file like: | |
| # G6C=24034 | |
| # H9E=24049 | |
| # and create the hash you'd expect | |
| # if instead you have something like: | |
| # G6C=24034,24036 | |
| # H9E=24049 | |
| # then use a block to do the specify the value | |
| def self.hash(file_name, separator='=', &block) |
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
| class String | |
| def starts_with?(str) | |
| self =~ /#{str}/ | |
| end | |
| end | |
| names_to_edid = File.open(File.dirname(__FILE__) + '/edid_names').read.split("\n"). | |
| collect {|line| edid, pruid, edname = line.split("|"); [edname.strip, edid.strip]}. | |
| inject({}) {|hash,e| hash[e.first] = e.last; hash } | |
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
| class Hash | |
| def +(other) | |
| (self.keys + other.keys).uniq.each do |key| | |
| if [self[key], other[key]].all? | |
| if self[key].is_a?(Hash) | |
| self[key] += other[key] | |
| elsif self[key].respond_to?(:+) | |
| self[key] += other[key] | |
| else | |
| raise "values for #{key} were neither hashes or summable" |
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
| Dir.glob("*").each do |pc| | |
| File.open(pc).read =~ /aug08cpocRidingProfileTitle>([^<]*)</ | |
| puts "#{pc},#{$1}" | |
| 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
| require 'rubygems' | |
| require 'mechanize' | |
| postal_codes = File.open("postal_codes.txt").read.split("\n") | |
| # randomize to make the pattern slightly harder to see in logs | |
| postal_codes = postal_codes.sort_by {|e| rand(10_000)} | |
| def filename(postcode) | |
| postcode.sub(' ', '') | |
| 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
| require 'rubygems' | |
| require 'mechanize' | |
| postal_codes = File.open("postal_codes.txt").read.split("\n") | |
| # randomize to make the pattern slightly harder to see in logs | |
| postal_codes = postal_codes.sort_by {|e| rand(10_000)} | |
| @agent = WWW::Mechanize.new do |a| | |
| a.user_agent_alias = 'Mac Safari' | |
| a.max_history = 1 |
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 'mechanize' | |
| postal_codes = File.open("postal_codes.txt").read.split("\n") | |
| # randomize to make the pattern slightly harder to see in logs | |
| postal_codes = postal_codes.sort_by {|e| rand(10_000)} | |
| @agent = WWW::Mechanize.new do |a| | |
| a.user_agent_alias = 'Mac Safari' | |
| a.max_history = 1 |