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
#!/usr/bin/env ruby
# Open a new tab in Terminal
# usage: tab [cmd]
# If cmd is specified, it will be run in new tab while old tab is reactivated.
# If no cmd, new tab is activated
require "rubygems"
require "appscript"
include Appscript
window = app("Terminal").windows.first
# Get your commit hash from git log
git revert b899e585972342c4c33426535c30722f1f1ca14c
# Commit message if required (defaults to Created commit abe8722: Revert "YOur message")
git pull
git push
# Win.
# 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.
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
module Locality::Search
def self.included(base)
base.class_eval do
class << self
def search(criteria)
logger.debug("search")
results = find_all_by_name(criteria)
if results.empty?

Poor Man's Deploy

  • Start a Sinatra server on port 4000
  • GET / to that server triggers a git pull and mod_rails restart
  • Hit port 4000 locally after pushing

Why?

@benschwarz
benschwarz / stats.rb
Created September 16, 2009 04:14 — forked from mojombo/stats.rb
# Run the given block +num+ times and then print out the mean, median, min,
# max, and stddev of the run. For example:
#
# irb> stats(10) { sleep(rand / 100) }
# mean: 5.99ms
# median: 6.76ms
# min: 1.49ms
# max: 9.28ms
# stddev: 2.54ms
def stats(num)
@benschwarz
benschwarz / stats.rb
Created September 16, 2009 01:30 — forked from mojombo/stats.rb
# Run the given block +num+ times and then print out the mean, median, min,
# max, and stddev of the run. For example:
#
# irb> stats(10) { sleep(rand / 100) }
# mean: 5.99ms
# median: 6.76ms
# min: 1.49ms
# max: 9.28ms
# stddev: 2.54ms
def stats(num)
A few things left to do:
* Ability to add default options for each PDF, rather than having to pass it to each generate_* method call
* Doesn't check if the pdf already exists. By default, which should it do?
- Overwrite the existing file. Let your users decide what they'd like to do here.
* Consider the inclusion of css, or even generated css templates using pre existing libraries (lesscss or yerk – sass.)
Anything else?
http://ujihisa.blogspot.com/2009/06/rubygems-best-practice.html