Skip to content

Instantly share code, notes, and snippets.

View desmondmonster's full-sized avatar

Desmond Bowe desmondmonster

View GitHub Profile
@desmondmonster
desmondmonster / beatr
Created October 23, 2015 13:15
nginx config for actioncable websockets
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream beatr_websocket {
server unix://tmp/puma.sock;
}
@desmondmonster
desmondmonster / gist:8461231
Created January 16, 2014 19:06
sample implementation for multiple exchange handling
def publish(routing_key, message, properties = {})
ensure_connection!(routing_key, message)
exchange = fetch_exchange(properties.delete(:exchange))
non_overridable_properties = {
routing_key: routing_key,
timestamp: Time.now.to_i,
content_type: 'application/json'
}
ctrl+c: 2.0.0p0 :001 > /Users/desmond/.rvm/gems/ruby-2.0.0-p0/gems/bunny-0.9.0/lib/bunny/socket.rb:41:in `read_nonblock': closed stream (IOError)
from /Users/desmond/.rvm/gems/ruby-2.0.0-p0/gems/bunny-0.9.0/lib/bunny/socket.rb:41:in `block in read_fully'
from /Users/desmond/.rvm/gems/ruby-2.0.0-p0/gems/bunny-0.9.0/lib/bunny/socket.rb:40:in `loop'
from /Users/desmond/.rvm/gems/ruby-2.0.0-p0/gems/bunny-0.9.0/lib/bunny/socket.rb:40:in `read_fully'
from /Users/desmond/.rvm/gems/ruby-2.0.0-p0/gems/bunny-0.9.0/lib/bunny/transport.rb:199:in `read_next_frame'
from /Users/desmond/.rvm/gems/ruby-2.0.0-p0/gems/bunny-0.9.0/lib/bunny/session.rb:696:in `init_connection'
from /Users/desmond/.rvm/gems/ruby-2.0.0-p0/gems/bunny-0.9.0/lib/bunny/session.rb:214:in `start'
from /Users/desmond/.rvm/gems/ruby-2.0.0-p0/gems/bunny-0.9.0/lib/bunny/session.rb:485:in `recover_from_network_failure'
from /Users/desmond/.rvm/gems/ruby-2.0.0-p0/gems/bunny-0.9.0/lib/bunny/session.rb:462:in `handle_network_failure'
@desmondmonster
desmondmonster / gist:3114439
Created July 15, 2012 02:05
active hash benchmark script
require 'rubygems'
require 'benchmark'
require 'active_hash'
def test_array(size=10000)
[].tap do |array|
(1..size).each do |i|
array << { :id => i, :name => "#{i}_string", :text => "text"}
end
end
jruby-1.6.7 :002 > require 'json'
jruby-1.6.7 :007 > str = '{"field1": "test"}'
=> "{"field1": "test"}"
jruby-1.6.7 :008 > JSON.parse(str)
=> {"field1"=>"test"}
jruby-1.6.7 :009 > _.class.name
=> "Hash"