Skip to content

Instantly share code, notes, and snippets.

View mperham's full-sized avatar

Mike Perham mperham

View GitHub Profile
@mperham
mperham / gist:2187468
Created March 24, 2012 20:20
blpop not accurate
redis 127.0.0.1:6379> blpop a, 1
(nil)
(1.49s)
redis 127.0.0.1:6379> blpop a, 1
(nil)
(1.02s)
redis 127.0.0.1:6379> blpop a, 1
(nil)
(1.51s)
redis 127.0.0.1:6379> blpop a, 1
@mperham
mperham / gist:2166351
Created March 23, 2012 02:46
Dalli benchmarks: MRI 1.9.3 vs JRuby 1.6.7
> rake bench
Testing with Rails 3.2.1
Using standard socket IO (jruby 1.6.7 (ruby-1.9.2-p312) (2012-02-22 3e82bc8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java])
Run options: --seed 22292
# Running tests:
Testing 2.0.0 with jruby 1.6.7 (ruby-1.9.2-p312) (2012-02-22 3e82bc8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]
Found memcached 1.4.13 in PATH
user system total real
@mperham
mperham / gist:2165749
Created March 23, 2012 00:21
jruby + dalli = unhappy
src/dalli> JRUBY_OPTS=--1.9 ruby test/benchmark_test.rb
Testing with Rails 3.2.1
/Users/mperham/.rvm/gems/jruby-1.6.7@dalli/gems/minitest-2.11.4/lib/minitest/unit.rb:647 warning: already initialized constant VERSION
/Users/mperham/.rvm/gems/jruby-1.6.7@dalli/gems/minitest-2.11.4/lib/minitest/unit.rb:1021 warning: already initialized constant PASSTHROUGH_EXCEPTIONS
/Users/mperham/.rvm/gems/jruby-1.6.7@dalli/gems/minitest-2.11.4/lib/minitest/unit.rb:1024 warning: already initialized constant SUPPORTS_INFO_SIGNAL
Using standard socket IO (jruby 1.6.7 (ruby-1.9.2-p312) (2012-02-22 3e82bc8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java])
Run options: --seed 40696
# Running tests:
@mperham
mperham / gist:2047504
Created March 15, 2012 23:03
Encoding issue
ArgumentError: invalid %-encoding (Men's Advance Lightweight Zip Tee
Channeled construction increases performance, decreases weight. 100% polyester wicks, breathes and dries quickly. Chitosan anti-microbial finish controls odor.
**break**
Wicking, fast drying, antimicrobial fabric is lightweight and comfortable
Flat-lock seams are rotated away from abrasion areas for comfort
2" stand-up collar and 8" front zip for thermoregulation
@mperham
mperham / convert.rake
Created March 15, 2012 17:44
Ruby script to update MySQL from Latin1 to UTF8 without data conversion
desc "convert a latin1 database with utf8 data into proper utf8"
task :convert_to_utf8 => :environment do
puts Time.now
dryrun = ENV['DOIT'] != '1'
conn = ActiveRecord::Base.connection
if dryrun
def conn.run_sql(sql)
puts(sql)
end
else
@mperham
mperham / thread_test.rb
Created March 11, 2012 03:02
Bug in ruby 1.9.3 threading?
trap 'INT' do
puts 'Got Ctrl-C'
puts Thread.current
puts Thread.main
puts Thread.main.status
# BUG BUG BUG
# This does not result in the main thread waking up from
# the Thread.stop call below.
Thread.main.run
puts Thread.main.status
@mperham
mperham / gist:2012730
Created March 10, 2012 19:54
Sinatra warnings
/Users/mperham/.rvm/gems/ruby-1.9.3-p125@sidekiq/gems/sinatra-1.3.2/lib/sinatra/base.rb:1305: warning: assigned but unused variable - e
/Users/mperham/.rvm/gems/ruby-1.9.3-p125@sidekiq/gems/sinatra-1.3.2/lib/sinatra/base.rb:1241:in `encoded': warning: URI.escape is obsolete
/Users/mperham/.rvm/gems/ruby-1.9.3-p125@sidekiq/gems/sinatra-1.3.2/lib/sinatra/base.rb:1242:in `encoded': warning: URI.escape is obsolete
/Users/mperham/.rvm/gems/ruby-1.9.3-p125@sidekiq/gems/sinatra-1.3.2/lib/sinatra/base.rb:1241:in `encoded': warning: URI.escape is obsolete
/Users/mperham/.rvm/gems/ruby-1.9.3-p125@sidekiq/gems/sinatra-1.3.2/lib/sinatra/base.rb:1242:in `encoded': warning: URI.escape is obsolete
(eval):1: warning: method redefined; discarding old app_file
/Users/mperham/.rvm/gems/ruby-1.9.3-p125@sidekiq/gems/sinatra-1.3.2/lib/sinatra/base.rb:987: warning: previous definition of app_file was here
/Users/mperham/.rvm/gems/ruby-1.9.3-p125@sidekiq/gems/sinatra-1.3.2/lib/sinatra/base.rb:1004: warning: method redefined; discard
@mperham
mperham / gist:1831203
Created February 14, 2012 22:39
Campfire deploy announcements
# Put this at the bottom of your config/deploy.rb
# Requires config file ~/.campfire.yml with your API token from
# your Campfire "My Info" page:
#
# token: lkjsadfsaduoi1u31oui3eh1kj2h
# roomid: 123456
# subdomain: acmeco
class Room
attr_accessor :config
@mperham
mperham / counter.go
Created December 27, 2011 22:37
Count the number of a given tag on a web page using Go
package main
import (
"os"
"fmt"
"strings"
"flag"
"http"
"html"
)
@mperham
mperham / gist:1379464
Created November 19, 2011 22:33
Flexibility without Dependency Injection
class TaxCode
GENERATORS = {
:us => lambda { |id| "US-#{id}" },
:br => lambda { |id| "#{id + 9}-BRA" },
}
def self.generate(code, id)
gen = GENERATORS[code] || raise ArgumentError, "No generator for country #{code}"
gen.call(id)
end