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
require 'rubygems' | |
require 'hpricot' | |
require 'open-uri' | |
require 'builder' | |
def get_subreddits(uri = 'http://www.reddit.com/reddits/') | |
reddits = [] | |
while uri | |
page = download_page(uri) |
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
# takes a hex value of a colour (0xffffff) and returns either black or white, which ever is easier to see | |
def black_or_white(hex) | |
rgb = {} | |
%w(r g b).inject(hex) {|a,i| rest, rgb[i] = a.divmod 256; rest} | |
r = rgb['r']/255 | |
g = rgb['g']/255 | |
b = rgb['b']/255 |
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
# Delete unnecessary files | |
run "rm public/index.html" | |
run "rm public/favicon.ico" | |
run "rm public/images/rails.png" | |
run "rm public/javascripts/prototype.js" | |
run "rm public/javascripts/effects.js" | |
run "rm public/javascripts/dragdrop.js" | |
run "rm public/javascripts/controls.js" | |
# Copy database.yml for distribution use |
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
# import content from an exported folder of html files from jumpchart.com | |
# TODO login and download the zip direct from jumpchart | |
require 'find' | |
require 'hpricot' | |
namespace :jumpchart do | |
desc 'Import pages from jumpchart' | |
task :import => :environment do | |
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
# from http://www.insiderpages.com/rubyonrails/2007/01/get-referring-search-engine-keywords.html | |
def setup_referring_keywords | |
# Check whether referring URL was a search engine result | |
referer = @request.env["HTTP_REFERER"] | |
unless referer.nil_or_empty? | |
search_referers = [ | |
[/^http:\/\/(www\.)?google.*/, 'q'], | |
[/^http:\/\/search\.yahoo.*/, 'p'], | |
[/^http:\/\/search\.msn.*/, 'q'], |
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
require 'rubygems' | |
require 'garb' # http://github.com/vigetlabs/garb/ | |
Garb::Session.login('[email protected]', 'password') | |
site = Garb::Profile.all.first | |
puts "Top 10 uri's in the past day on #{site.title}:" | |
r = Garb::Report.new(site) | |
r.metrics << :pageviews |
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
require 'rubygems' | |
require 'garb' # http://github.com/vigetlabs/garb/ | |
require 'sparklines' # http://github.com/topfunky/sparklines | |
Garb::Session.login('[email protected]', 'password') | |
site = Garb::Profile.all.first | |
days = [] | |
length = 86400 |
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
$.ajaxSettings.accepts.html = $.ajaxSettings.accepts.script; |
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
def counties_options | |
returning '' do |options| | |
options << content_tag(:optgroup, :label => 'England') do | |
options_for_select ['Bedfordshire', 'Berkshire', 'Bristol', 'Buckinghamshire', 'Cambridgeshire', 'Cheshire', 'City of London', 'Cornwall', | |
'Cumbria', 'Derbyshire', 'Devon', 'Dorset', 'Durham', 'East Riding of Yorkshire', 'East Sussex', 'Essex', 'Gloucestershire', | |
'Greater London', 'Greater Manchester', 'Hampshire', 'Herefordshire', 'Hertfordshire', 'Isle of Wight', 'Kent', 'Lancashire', | |
'Leicestershire', 'Lincolnshire', 'Merseyside', 'Norfolk', 'North Yorkshire', 'Northamptonshire', 'Northumberland', | |
'Nottinghamshire', 'Oxfordshire', 'Rutland', 'Shropshire', 'Somerset', 'South Yorkshire', 'Staffordshire', 'Suffolk', 'Surrey', | |
'Tyne and Wear', 'Warwickshire', 'West Midlands', 'West Sussex', 'West Yorkshire', 'Wiltshire', 'Worcestershire'] | |
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
# is_paranoid shoulda macro | |
def self.should_be_paranoid | |
klass = model_class | |
should_have_db_column :deleted_at | |
context "A #{klass.name}" do | |
should "be paranoid (it will not be deleted from the database)" do | |
assert klass.is_paranoid | |
assert klass.included_modules.include?(IsParanoid::InstanceMethods) |
OlderNewer