Skip to content

Instantly share code, notes, and snippets.

View cpuguy83's full-sized avatar
🐶

Brian Goff cpuguy83

🐶
View GitHub Profile
@cpuguy83
cpuguy83 / mongoid_conn_pool.rb
Last active December 19, 2015 11:09
Working out connection pooling for Mongoid. Right now in Mongoid every thread gets a new connection, and is not closing those connections when the thread is complete.
require 'thread'
require 'thread_safe'
require 'monitor'
module Mongoid
def with_session(&block)
Sessions.with_session(&block)
end
module Config
option :session_pool_size, :default => 5
@cpuguy83
cpuguy83 / gist:5940398
Created July 6, 2013 16:31
Puma 2.3 fails to start
An exception occurred running /home/deployer/apps/emp/shared/bundle/rbx/1.9/bin/puma
no such file to load -- puma/single (LoadError)
Backtrace:
Rubinius::CodeLoader#load_error at kernel/common/codeloader.rb:410
Rubinius::CodeLoader#resolve_require_path at kernel/common/codeloader.rb:397
{ } in Rubinius::CodeLoader#require at kernel/common/codeloader.rb:105
Rubinius.synchronize at kernel/bootstrap/rubinius.rb:149
Rubinius::CodeLoader#require at kernel/common/codeloader.rb:104
Rubinius::CodeLoader.require at kernel/common/codeloader.rb:226
@cpuguy83
cpuguy83 / gist:5917771
Created July 3, 2013 13:16
Rack error on postgres integer array for has_many relationship
2013-07-03 09:11:39 -0400: Rack app error: #<TypeError: expected Array (got String) for param `user_ids'>
/Users/bgoff/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/utils.rb:114:in `normalize_params'
/Users/bgoff/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/utils.rb:128:in `normalize_params'
/Users/bgoff/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/multipart/parser.rb:31:in `block in parse'
/Users/bgoff/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/multipart/parser.rb:17:in `loop'
/Users/bgoff/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/multipart/parser.rb:17:in `parse'
/Users/bgoff/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/multipart.rb:25:in `parse_multipart'
/Users/bgoff/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/request.rb:377:in `parse_multipart'
/Users/bgoff/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/request.rb:203:in `POST'
/Users/bgoff/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/methodoverride.rb:26:in `method_override'
@cpuguy83
cpuguy83 / foo.rb
Last active December 18, 2015 04:29
Serializes model for use with https://github.com/rjackson/pivot.js
class Foo < ActiveRecord::Base
include Pivotable
# calls method on self, labeled as the method name
pivot :name
# calls method on self and labels it with a custom name
pivot :some_awful_field_name, as: :a_better_field_name
# Calls value from another object/method than self
# Without the call to `as` this example would be named "some_related_object_bar", but with the `as`
@cpuguy83
cpuguy83 / primitive_write_failed_exception
Created May 31, 2013 13:54
Sidekiq + RBX - FFI::Pointer#primitive_write_int primitive failed
kernel/platform/pointer_accessors.rb:671:in `write_int'
/home/deployer/.rvm/rubies/rbx-head/lib/19/socket.rb:86:in `setsockopt'
kernel/platform/pointer.rb:308:in `new'
/home/deployer/.rvm/rubies/rbx-head/lib/19/socket.rb:85:in `setsockopt'
/home/deployer/apps/emp/shared/bundle/rbx/1.9/gems/moped-1.4.5/lib/moped/sockets/connectable.rb:156:in `connect'
/home/deployer/.rvm/rubies/rbx-head/lib/19/timeout.rb:149:in `timeout'
/home/deployer/apps/emp/shared/bundle/rbx/1.9/gems/moped-1.4.5/lib/moped/sockets/connectable.rb:151:in `connect'
/home/deployer/apps/emp/shared/bundle/rbx/1.9/gems/moped-1.4.5/lib/moped/connection.rb:36:in `connect'
/home/deployer/apps/emp/shared/bundle/rbx/1.9/gems/moped-1.4.5/lib/moped/node.rb:557:in `connect'
/home/deployer/apps/emp/shared/bundle/rbx/1.9/gems/moped-1.4.5/lib/moped/node.rb:137:in `ensure_connected'
@cpuguy83
cpuguy83 / gist:5673412
Created May 29, 2013 20:05
chef-server failed install
Unpacking chef (from chef_11.4.4-2.ubuntu.11.04_amd64.deb) ...
dpkg-deb (subprocess): short read on buffer copy for failed to write to pipe in copy
dpkg-deb: error: subprocess paste returned error exit status 2
dpkg: error processing chef_11.4.4-2.ubuntu.11.04_amd64.deb (--install):
short read on buffer copy for backend dpkg-deb during `opt/chef/embedded/share/terminfo/m/mrxvt-256color'
Errors were encountered while processing:
chef_11.4.4-2.ubuntu.11.04_amd64.deb
@cpuguy83
cpuguy83 / data.log
Last active December 17, 2015 20:48
Rbx crash with Sidekiq and no jit running, commit# 2dc4bdaa
$1 = {<rubinius::Object> = {<rubinius::ObjectHeader> = {header = {f = {obj_type = rubinius::DataType, zone = rubinius::YoungObjectZone, age = 2, meaning = rubinius::eAuxWordHandle, Forwarded = 1,
Remember = 0, Marked = 2, InImmix = 0, Pinned = 0, Frozen = 0, Tainted = 0, Untrusted = 0, LockContended = 0, unused = 0, aux_word = 30523}, flags64 = 131095288007196},
klass_ = 0x92184b0, ivars_ = 0xb7c52ed0, __body__ = 0xb7abef58}, static type = <optimized out>}, static type = rubinius::DataType, internal_ = 0x9eca418, freed_ = false}
(gdb)
@cpuguy83
cpuguy83 / gist:5665421
Created May 28, 2013 19:29
GDB sidekiq backtrace with JIT
#0 jit_stub_string_equal (state=0x99ceb34c, call_frame=0x99ce21a8, recv=0x1a, ra0=0xb79083f4) at vm/gen/jit_primitives.cpp:7466
ret = <value optimized out>
self = 0x0
#1 0x9b667914 in ?? ()
No symbol table info available.
#2 0x082fd9b2 in rubinius::CompiledCode::specialized_executor (state=0x99ceb34c, call_frame=0x99ce2470, exec=0x99ce21a8, mod=0xb589c4c0, args=...) at vm/builtin/compiledcode.cpp:250
cls = <value optimized out>
id = 2222
v = 0x99ce21a8
target = 0x99ce2220
@cpuguy83
cpuguy83 / gist:5663189
Created May 28, 2013 14:34
With JIT disabled?
Error: signal SIGSEGV
[[Backtrace]]
rbx[0x81bb41a]
[0xb7868400]
rbx(_ZN8rubinius4Data8finalizeEPNS_5StateEPS0_+0xd6)[0x8300636]
rbx(_ZN8rubinius16FinalizerHandler8finalizeEPNS_5StateE+0x248)[0x8394b58]
rbx(_ZN8rubinius16FinalizerHandler7performEPNS_5StateE+0xa4)[0x83963e4]
rbx(_ZN8rubinius23finalizer_handler_trampEPNS_5StateE+0x27)[0x8396707]
rbx(_ZN8rubinius6Thread13in_new_threadEPv+0x3d8)[0x8361928]
@cpuguy83
cpuguy83 / gist:5653837
Created May 26, 2013 19:55
New crash on Rbx commit# 2dc4bdaa
Backtrace:
rbx[0x81bb41a]
[0xb7863400]
rbx(jit_stub_string_equal+0x5e)[0x82115be]
[0xa0340d54]
rbx(_ZN8rubinius12CompiledCode20specialized_executorEPNS_5StateEPNS_9CallFrameEPNS_10ExecutableEPNS_6ModuleERNS_9ArgumentsE+0x92)[0x82fd9b2]
rbx(_ZN8rubinius15MonoInlineCache11check_cacheEPNS_5StateEPNS_8CallSiteEPNS_9CallFrameERNS_9ArgumentsE+0x4f)[0x8323d8f]
rbx(_ZN8rubinius11MachineCode11interpreterEPNS_5StateEPS0_PNS_20InterpreterCallFrameE+0x1fc5)[0x81dbbf5]
rbx(_ZN8rubinius11MachineCode19execute_specializedINS_16GenericArgumentsEEEPNS_6ObjectEPNS_5StateEPNS_9CallFrameEPNS_10ExecutableEPNS_6ModuleERNS_9ArgumentsE+0x5ac)[0x8227c2c]
rbx(_ZN8rubinius15PolyInlineCache11check_cacheEPNS_5StateEPNS_8CallSiteEPNS_9CallFrameERNS_9ArgumentsE+0xd1)[0x834dce1]