Skip to content

Instantly share code, notes, and snippets.

View andrew's full-sized avatar

Andrew Nesbitt andrew

View GitHub Profile
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)
# 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
@andrew
andrew / rails_template.rb
Created April 2, 2009 12:39 — forked from ioptics/gist:88895
Rails template
# 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
# 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
# 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'],
require 'rubygems'
require 'garb' # http://github.com/vigetlabs/garb/
Garb::Session.login('analytics@email.com', '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
require 'rubygems'
require 'garb' # http://github.com/vigetlabs/garb/
require 'sparklines' # http://github.com/topfunky/sparklines
Garb::Session.login('analytics@email.com', 'password')
site = Garb::Profile.all.first
days = []
length = 86400
$.ajaxSettings.accepts.html = $.ajaxSettings.accepts.script;
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
# 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)