Skip to content

Instantly share code, notes, and snippets.

View mperham's full-sized avatar

Mike Perham mperham

View GitHub Profile
@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: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 / 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:11262832
Created April 24, 2014 17:33
FCC comment
Allowing ISPs to charge for different levels of access to consumers
creates an uneven playing field for Internet-based companies. As a
consumer, I already pay an ISP monthly to provide me a level of service when
accessing the internet. I expect that access to be fair for all
companies so that I have equal access to all services on the Internet.
Allowing large companies to pay for faster "lanes" means that small
companies cannot compete fairly and hurts the normal pace of
innovation. Please keep Net Neutrality in place so the Internet
continues to be a place of innovation and not monied incumbents.
@mperham
mperham / gc opts
Last active August 29, 2015 14:01
Ruby 2.1.2 memory bloat/leak
> pp ENV.select {|x| x =~ /^RUBY/ }
{"RUBY_GC_HEAP_GROWTH_FACTOR"=>"1.3",
"RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR"=>"1.3",
"RUBY_GC_HEAP_INIT_SLOTS"=>"600000",
"RUBY_GC_MALLOC_LIMIT"=>"90000000",
"RUBYOPT"=>"-rbundler/setup",
"RUBYLIB"=>
"/usr/local/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib"}
@mperham
mperham / gist:7d763bdc42465caf17c7
Last active August 29, 2015 14:02
Rule execution

I want to build a system which uses rules. These rules will change hourly (i.e. "this rule is effective from 2pm to 6pm"). The rules must support arbitrarily complex logic on just 2-3 pre-defined variables and result in a boolean:

item.a > 10 && item.b == 0 || item.category == FOOTWEAR

These rules will be executed hundreds of times per second so I can't afford the overhead of plain old eval. I want to reload the current effective ruleset from the database hourly, precompile each rule's logic string and execute it via the quickest method possible. It might look something like this:

class Rule
@mperham
mperham / repro.md
Created July 22, 2015 21:45
Sidekiq / Rails 5 interlockup
git clone git://github.com/mperham/sidekiq
cd sidekiq && git checkout rails5
cd myapp && bundle
bundle exec sidekiq
# in another terminal tab
bundle exec rails s

Now hit http://localhost:3000/work to create a random set of jobs for sidekiq to perform.

diff --git a/lib/starling/handler.rb b/lib/starling/handler.rb
index 4ab2960..1bde8ac 100644
--- a/lib/starling/handler.rb
+++ b/lib/starling/handler.rb
@@ -56,6 +56,7 @@ STAT queue_%s_age %d\r\n".freeze
SHUTDOWN_COMMAND = /\Ashutdown\r\n/m
+ QUIT_COMMAND = /\Aquit\r\n/m
diff --git a/vendor/plugins/geokit/lib/geo_kit/acts_as_mappable.rb b/vendor/plugins/geokit/lib/geo_kit/acts_as_mappable.rb
index c6c5eba..23dbab1 100644
--- a/vendor/plugins/geokit/lib/geo_kit/acts_as_mappable.rb
+++ b/vendor/plugins/geokit/lib/geo_kit/acts_as_mappable.rb
@@ -377,20 +377,22 @@ module GeoKit
lat = deg2rad(origin.lat)
lng = deg2rad(origin.lng)
multiplier = units_sphere_multiplier(units)
- case connection.adapter_name.downcase
- when "sqlite"
require 'rubygems'
gem 'rails', '2.2.2'
gem 'json', '1.1.3' # or json_pure, both break
# Switch these requires and it works
require 'json'
require 'activesupport'
data = { :a => [1,2,3] }
puts data.to_json