Skip to content

Instantly share code, notes, and snippets.

View mperham's full-sized avatar

Mike Perham mperham

View GitHub Profile
@mperham
mperham / bench.rb
Last active August 29, 2015 13:57
Sidekiq performance 2014
require 'sidekiq'
class LazyWorker
include Sidekiq::Worker
def perform
# nothing
end
end
Sidekiq.configure_client do |config|
@mperham
mperham / gist:9864177
Created March 29, 2014 22:38
mime-types - such garbage
640 ::CLASS
645 /Users/mikep/.rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:ARRAY
676 /Users/mikep/.rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/stub_specification.rb:21:STRING
722 /Users/mikep/.rubies/ruby-2.1.1/lib/ruby/2.1.0/x86_64-darwin13.0/openssl.bundle:0:STRING
724 /Users/mikep/.rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/specification.rb:1338:OBJECT
734 /Users/mikep/.rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/requirement.rb:92:ARRAY
734 /Users/mikep/.rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/requirement.rb:92:STRING
872 /Users/mikep/.rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/requirement.rb:53:OBJECT
876 /Users/mikep/.gem/ruby/2.1.1/gems/sprockets-2.10.0/lib/sprockets/mime.rb:1:STRING
884 /Users/mikep/.gem/ruby/2.1.1/gems/mime-types-1.25/lib/mime/types.rb:423:STRING
@mperham
mperham / gist:8922782
Created February 10, 2014 19:43
Rubby numeric handling
> require 'bigdecimal'
=> true
> Float('foo')
ArgumentError: invalid value for Float(): "foo"
from (irb):2:in `Float'
from (irb):2
from /Users/mikep/.rubies/ruby-2.0.0-p353/bin/irb:12:in `<main>'
> Integer('foo')
ArgumentError: invalid value for Integer(): "foo"
from (irb):3:in `Integer'
@mperham
mperham / gist:8463495
Created January 16, 2014 21:10
Using #join with a Sidekiq::Batch in Rails to parallelize data migration
class MoveInventoryUpdatesToS3 < ActiveRecord::Migration
def up
batch = Sidekiq::Batch.new
batch.jobs do
InventoryUpdate.where("content is not null").pluck(:id).each do |iuid|
InventoryUpdate.delay.send_to_s3(iuid)
end
end
# wait for all jobs to finish
@mperham
mperham / gist:8323180
Created January 8, 2014 19:40
Using tempfile
# Use open to ensure tempfile is cleaned up asap
Tempfile.open("somename") do |tfile|
# Stage 1 - create the tempfile with some data
tfile.write "some bytes"
tfile.close
# Stage 2 - use the tempfile
File.open(tfile.path) do |file|
assert "some bytes", file.read
@mperham
mperham / yolo.rb
Created July 12, 2013 17:15
Have 100s of models and thousands of tests? Prefer simplicity over security when upgrading to Rails4? YOLO!
class ActiveRecord::Base
class << self
def inherited_yolo(klass)
old_inherited(klass)
klass.attr_accessible(*klass.column_names.map(&:to_sym)) unless klass.abstract_class?
end
alias_method :old_inherited, :inherited
alias_method :inherited, :inherited_yolo
end
end
@mperham
mperham / gist:5050311
Created February 27, 2013 18:31
monit causes memcached performance issues
--- a/site-cookbooks/monit/templates/default/memcached.conf.erb
+++ b/site-cookbooks/monit/templates/default/memcached.conf.erb
@@ -2,5 +2,5 @@ check process memcached
with pidfile /var/run/memcached.pid
start program = "/etc/init.d/memcached start"
stop program = "/etc/init.d/memcached stop"
- if failed port 11211 protocol memcache 4 times within 6 cycles then restart
+ if failed port 11211 4 times within 6 cycles then restart
if 5 restarts within 5 cycles then timeout
1 (M=55122) ~/src/theclymb> rvm info
ruby-1.9.3-p125@theclymb3:
system:
uname: "Darwin Mikes-MacBook-Air.local 12.2.0 Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64"
system: "osx/10.8/x86_64"
bash: "/bin/bash => GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12)"
zsh: "/bin/zsh => zsh 4.3.11 (i386-apple-darwin12.0)"
@mperham
mperham / gist:4012475
Created November 4, 2012 16:22
2.0.0.rc1 crash
.FF..........................................................................................................................................................................................................
---------------------------------------------
CRASH: A fatal error has occurred.
Backtrace:
0 rbx 0x000000010c04f6d0 _ZN8rubiniusL12segv_handlerEi + 544
1 libsystem_c.dylib 0x00007fff91c31cfa _sigtramp + 26
2 libsystem_c.dylib 0x00007fff91c2f3c8 malloc_zone_malloc + 77
3 rbx 0x000000010c16a202 _ZN8rubinius12CompiledCode4Info4markEPNS_6ObjectERNS_10ObjectMarkE + 318
4 rbx 0x000000010c20075e _ZN8rubinius16GarbageCollector11scan_objectEPNS_6ObjectE + 456
@mperham
mperham / gist:3988273
Created October 31, 2012 16:56
1.9.3-p125 vs 1.9.3-p286-falcon
(speedup_rails_startup=fa456 .rvmrc bin/) ~/src/clymb> !time
time bundle exec rake environment
real 0m7.853s
user 0m6.485s
sys 0m1.129s
(speedup_rails_startup=fa456 .rvmrc bin/) ~/src/clymb> time bundle exec rake environment
real 0m7.478s
user 0m6.378s