Skip to content

Instantly share code, notes, and snippets.

View benschwarz's full-sized avatar
🏁
Making the web fast

Ben Schwarz benschwarz

🏁
Making the web fast
View GitHub Profile
require 'rubygems'
require 'sinatra'
set :environment, :production
set :raise_errors, true
run Sinatra::Application
get '/geoCheck' do
<<-EOL
Processing Admin::AssetsController#create (for 127.0.0.1 at 2009-03-03 14:45:51) [POST]
Parameters: {"plain"=>"false", "action"=>"create", "authenticity_token"=>"1a06b78f94bef113c58c757304fedc75b3832803", "linkback"=>"", "controller"=>"admin/assets", "asset"=>{"name"=>"Swellnet logo file test", "uploaded_data"=>#<ActionController::UploadedStringIO:0x550fba4>, "caption"=>"", "alt"=>""}, "target"=>""}
DynamicJavascript Load (0.3ms) SELECT * FROM `dynamic_javascripts` WHERE (`dynamic_javascripts`.`ad_type` = 'Leaderboard: 720x90px') LIMIT 1
DynamicJavascript Load (0.2ms) SELECT * FROM `dynamic_javascripts` WHERE (`dynamic_javascripts`.`ad_type` = 'Island: 300x200px') LIMIT 1
DynamicJavascript Load (0.1ms) SELECT * FROM `dynamic_javascripts` WHERE (`dynamic_javascripts`.`ad_type` = 'Gallery: 160x600px') LIMIT 1
Cache hit: System.Message.Invitation ({})
Cache hit: System.Message.Login ({})
Cache miss: Surfcam.feature ({})
Surfcam Load (0.2ms) SELECT * FROM `surfcams` WHERE (featured = tru
$ gem search webrat -r
*** REMOTE GEMS ***
ERROR: http://gems.github.com does not appear to be a repository
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
bad response Not Found 404 (http://gems.github.com/yaml)
Transfigr.add(:xml, :active_record_admin) do
match :any do |object|
object === ActiveRecord
object.user.admin?
end
def format(opts)
# do admin stuff here
end
# Monitor HTTP requests being made from your machine with a one-liner..
# Replace "en1" below with your network interface's name (usually en0 or en1)
sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*"
# OR.. to be able to use as "httpdump" from anywhere, drop this into ~/.bash_profile:
# (again replace "en1" with correct network interface name)
alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*""
# All the above tested only on OS X.
Smoke.feed(:slashdot) do
url "http://slashdot.org/index.rdf"
emit do
rename(:url => :link)
end
end
class A
def initialize(foo)
dispatch if respond_to? dispatch
end
end
class B < A
def dispatch
puts "called dispatch"
end
Smoke.feed(:twitter) do
url "http://twitter.com/statuses/user_timeline/14431882.rss"
discard :title, /(@|#)/
end
Smoke.feed(:delicious) do
url "http://feeds.delicious.com/v2/rss/bschwarz?count=15"
end
Smoke.data(:flickr) do
desc "Reset and run test suite"
task :ci => ["environment:force:test", "gems:install", :environment] do
Rake::Task["db:reset"].invoke
Rake::Task["db:bootstrap"].invoke
Rake::Task["spec"].invoke
end
# For protecting production
namespace :environment do
postcodes = FasterCSV.read(data_source_for("postcodes.csv"))
postcodes.each do |(post_code, name, state_name, _, _, _, _, _, _, category)|
if category.squish == "Delivery Area"
post_code = sprintf("%04d", post_code.to_i)
state = State.find_or_create_by_name(state_name)
Locality.create(:post_code => post_code, :name => name, :state => state)
end
end