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
validateAddress : function(addr) { | |
that = this; | |
this.geocoder.geocode({'address': addr, 'region' : 'us'}, function(results, status){ | |
if (status == google.maps.GeocoderStatus.OK) { | |
that.location_type = results[0]['geometry']['location_type']; | |
if (that.isValidLocationType()) { | |
that.followValidAddress(); | |
that.cur_google_suggestion = results[0].formatted_address; | |
} else { | |
// if it's not a valid address or zip, we'll *assume* it's a facility search |
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 'rest_client' | |
require 'nokogiri' | |
require 'pp' | |
def escape_csv(string) | |
string.gsub(/,/,'/') | |
end | |
class Crunch |
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
begin | |
ScraperWiki | |
rescue NameError | |
require 'rest_client' | |
ScraperWiki = Class.new do | |
def self.scrape(url) | |
RestClient.get(url) | |
end | |
def self.save(unique_keys=[],data={}) |
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
# this stuff just allows you | |
# to run the script outside ScraperWiki | |
begin | |
ScraperWiki | |
rescue NameError | |
require 'rest_client' | |
ScraperWiki = Class.new do | |
def self.scrape(url) | |
RestClient.get(url) |
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
def import(stat, &blk) | |
puts "trying #{stat}" | |
begin | |
block_given? ? blk.call : Object.const_get(stat).import(@date) | |
rescue GatticaError => exception | |
puts "*** got a GA error: #{exception} ***" | |
sleep 10 | |
retry | |
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
task :import_stat_range => :environment do | |
entity = ENV['ENTITY'] | |
start_date = ENV['START_DATE'].to_date | |
end_date = ENV['END_DATE'] ? ENV['END_DATE'].to_date : start_date | |
Entity.import_range(entity,start_date..end_date) | |
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
def sanitize_callback(callback) | |
if callback.nil? | |
return | |
end | |
callback=~/^(.{5}?)(\d?)/ | |
return nil if callback.length == 0 | |
return nil if $1 != "jsonp" | |
return nil if $2 == "" | |
return nil if callback.length > 128 | |
return callback |
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
def overwrite_stat | |
return if %w[Page Referrer PixelPingStory TwitterStory FacebookFan TwitterFollower].include?(self.entity.type.to_s) | |
new_count = self.count | |
existing_stat = Kernel.const_get(self.entity.type.to_s).first.stats.where(:count_date => self.count_date)[0] | |
if existing_stat | |
self.id = existing_stat.id | |
reload | |
@new_record = false | |
self.count = new_count |
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
makePctGraphs : function(stat) { | |
var el,stat_ary,max,pct_ary; | |
el = "tr." + stat + "_row td .county_stat_fig"; | |
stat_ary = _(this.$(el)).map(function(q) { | |
return Number($(q).attr("data-stat-val").replace(/[\$,]/g,'').replace(/(\.(.+)?)?$/,'')); | |
}); | |
max = _(stat_ary).max(); | |
pct_ary = _(stat_ary).map(function(q) { | |
return Number(((q / max) * 100).toFixed(2)); |
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'rest_client' | |
require 'nokogiri' | |
USER_AGENT = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.231 Safari/534.10" | |
def filename(url) | |
URI::parse(url).path.gsub(/^.+\/(.+)$/,'\1') |