Skip to content

Instantly share code, notes, and snippets.

View sferik's full-sized avatar

Erik Berlin sferik

View GitHub Profile
sferik / 404_image_swap.js
Created August 11, 2009 20:14
JQuery code to swap out broken images with a replacement image.
View 404_image_swap.js
$(document).ready(function() {
$(this).attr('src', 'not_found.png');
View to_tags.rb
include Stemmable
class String
def to_tags
# lower case
# replace new lines, numbers, and puncuation with spaces
# break words on spaces
# get the word stem
# remove duplicates
# removed stems less than 3 letters
View classes.rb
#!/usr/bin/env ruby
nodes = []
edges = {}
ObjectSpace.each_object(Class) do |klass|
# Skip classes outside the global namespace
next if klass.to_s.include?(':')
# Skip classes like ARGF.class
next if klass.to_s.include?('.')
View winner.rb
require 'curb'
require 'json'
followers_response = Curl::Easy.http_get("")
followers = JSON.parse(followers_response.body_str)
winner_id = followers[rand(followers.length)]
users_response = Curl::Easy.http_get("{winner_id}.json")
winner = JSON.parse(users_response.body_str)
puts "We have a winner!"
sferik / config.rb
Created November 20, 2009 00:59 — forked from merbjedi/config.rb
MerbAdmin DSL
View config.rb
MerbAdmin.config User do
label "Users" # @model.pretty_name
list do
before do
puts "Called before list"
fields :name, :description # All columns
filters :publication_date, :retired # All booleans
sferik / 1000 Twitter API Requests (JSON)
Created December 10, 2009 03:28
Twitter API Benchmarks
View 1000 Twitter API Requests (JSON)
$ ab -n 1000 -c 10
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd,
Licensed to The Apache Software Foundation,
Benchmarking (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
# This script is an adaptation from
# It expects stdin input from mysqldump with the following params:
# mysqldump --skip-extended-insert --add-drop-table --compatible=ansi --skip-add-locks --skip-comments --skip-disable-keys --skip-set-charset
# Note: Don't use --skip-quote-names as this script expects quoted names
# Note: This script imports boolean values as they are stored in Mysql, e.g., as the integers 0 and 1.
# As a result, boolean fields need to be further normalized after this transform step
# such that false field values are 'f' and true field values are 't', which is
sferik / gist:269793
Created January 5, 2010 22:13 — forked from carllerche/gist:177377 is slow
View gist:269793
require "rubygems"
require "rbench"
def noop
end do
column :one, :title => "Unthreaded"
column :two, :title => "Threaded"
View gist:572069
$ rake test_mysql
(in /Users/erik/projects/rails/activerecord)
/opt/local/bin/ruby -I"lib:test:test/connections/native_mysql" "/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/cases/aaa_create_tables_test.rb" "test/cases/active_schema_test_mysql.rb" "test/cases/adapter_test.rb" "test/cases/aggregations_test.rb" "test/cases/ar_schema_test.rb" "test/cases/associations/belongs_to_associations_test.rb" "test/cases/associations/callbacks_test.rb" "test/cases/associations/cascaded_eager_loading_test.rb" "test/cases/associations/eager_load_includes_full_sti_class_test.rb" "test/cases/associations/eager_load_nested_include_test.rb" "test/cases/associations/eager_singularization_test.rb" "test/cases/associations/eager_test.rb" "test/cases/associations/extension_test.rb" "test/cases/associations/habtm_join_table_test.rb" "test/cases/associations/has_and_belongs_to_many_associations_test.rb" "test/cases/associations/has_many_associations_test.rb" "test/cases/associations/has_many_through_
sferik / twitter_ssl_bench.rb
Created October 28, 2010 21:11
Twitter API SSL Benchmarks
View twitter_ssl_bench.rb
require 'rubygems'
require 'rbench'
require 'twitter'
class Bench
def self.setup
Twitter.configure do |config|
config.consumer_key = CONSUMER_KEY
config.consumer_secret = CONSUMER_SECRET
config.oauth_token = OAUTH_TOKEN