Skip to content

Instantly share code, notes, and snippets.

$ rbx mongo_hang.rb
Uploading file to grid (1)
An exception occurred running mongo_hang.rb
Cannot serialize an object of class Time into BSON. (BSON::InvalidDocument)
Backtrace:
BSON::BSON_C.serialize at /opt/rubinius/gems/1.8/gems/bson-1.0.2
/lib/../lib/bson/bson_c.rb:24
Mongo::Collection#insert_documents {} at /opt/rubinius/gems/1.8/gems
/mongo-1.0.2/lib/../lib/mongo
Operation failed with the following exception: connection closed
/app/dradis/.bundle/ruby/1.8/gems/mongo-1.0.2/lib/../lib/mongo/connection.rb:717:in `receive_message_on_socket'
/app/dradis/.bundle/ruby/1.8/gems/mongo-1.0.2/lib/../lib/mongo/connection.rb:614:in `receive_header'
/app/dradis/.bundle/ruby/1.8/gems/mongo-1.0.2/lib/../lib/mongo/connection.rb:607:in `receive'
/app/dradis/.bundle/ruby/1.8/gems/mongo-1.0.2/lib/../lib/mongo/connection.rb:403:in `receive_message'
/app/dradis/.bundle/ruby/1.8/gems/mongo-1.0.2/lib/../lib/mongo/connection.rb:401:in `synchronize'
/app/dradis/.bundle/ruby/1.8/gems/mongo-1.0.2/lib/../lib/mongo/connection.rb:401:in `receive_message'
/app/dradis/.bundle/ruby/1.8/gems/mongo-1.0.2/lib/../lib/mongo/cursor.rb:347:in `send_initial_query'
/app/dradis/.bundle/ruby/1.8/gems/mongo-1.0.2/lib/../lib/mongo/cursor.rb:324:in `refill_via_get_more'
/app/dradis/.bundle/ruby/1.8/gems/mongo-1.0.2/lib/../lib/mongo/cursor.rb:319:in `num_remaining'
$ rails c
Loading development environment (Rails 3.0.0.rc)
irb(main):001:0> class Person
irb(main):002:1> include Mongoid::Document
irb(main):003:1> field :first_name
irb(main):004:1> field :last_name
irb(main):005:1> attr_accessible :first_name, :last_name
irb(main):006:1> end
NoMethodError: undefined method `attr_accessible' for Person:Class
from (irb):5
@emk
emk / countdown.coffee
Created September 19, 2010 02:17
Count down from 10, using gradual display in a browser
sys = require "sys"
http = require "http"
# Run thunk n times.
repeat = (n, thunk) ->
thunk() for i in [0...n]
server = http.createServer (request, response) ->
response.writeHead 200, "Content-type": "text/html"
@emk
emk / comet_client.coffee
Created September 19, 2010 03:39
Real-time Comet with Faye, Node.js and Coffee
# Client-side Comet code. See comet_server.coffee for instructions.
client = new Faye.Client '/faye', timeout: 90
# Attach a security key to all our subscription messages.
client.addExtension
outgoing: (msg, callback) ->
return callback(msg) unless msg.channel is '/meta/subscribe'
(msg.ext ?= {}).authToken = 'secret'
callback(msg)
@emk
emk / switch-indentation.coffee
Created September 20, 2010 14:43
Indenting if and switch in CoffeeScript
# Here's the syntax for 'if'. The 'else' is flush with the headword.
if day is "Tue"
go relax
else
go work
# Here's the syntax for 'switch'. The 'when' and 'else' must be indented.
switch day
when "Tue"
go relax
@emk
emk / binding.coffee
Created September 20, 2010 23:36
Coffee: What's the best way to bind a member function?
# I've been asked not to call __bind directly. :-)
bind = (func, context) ->
(-> func.apply context, arguments)
class BindingMemberFunctions
sampleAjaxCalls: ->
# One wrapper, created each time we call.
ajax bind(@onAjaxError, this)
# Two wrappers, both created each time we call.
ajax => @onAjaxError arguments...
14 Oct 16:35:11 - Client 41187256830744445 disconnected
14 Oct 16:35:12 - Client 9686517922673374 disconnected
14 Oct 16:35:18 - Client 5149066185113043 disconnected
14 Oct 16:36:10 - Client 6712711281143129 connected
14 Oct 16:36:10 - Client 05666851415298879 connected
14 Oct 16:36:35 - Client 8900371692143381 connected
14 Oct 16:36:36 - Data incorrectly framed by UA. Dropping connection
14 Oct 16:36:36 - Client 8900371692143381 disconnected
14 Oct 16:36:36 - Client 5476035575848073 connected
14 Oct 16:36:36 - Client 4367445863317698 connected
@emk
emk / gist:718447
Created November 28, 2010 00:50
Rubinius test failures from 'rake' on Ubuntu 10.10 x86
1)
File.read raises a Errno::EISDIR when passed a path that is a directory FAILED
Expected Errno::EISDIR but got Errno::EINVAL (Invalid argument - read(2) failed)
/expectations.rb:15
{ } in main.__script__ at spec/ruby/core/file/shared/read.rb:6
Kernel(Object)#instance_eval at kernel/common/eval.rb:164
{ } in Enumerable(Array)#all? at kernel/common/enumerable.rb:205
Array#each at kernel/bootstrap/array.rb:71
Enumerable(Array)#all? at kernel/common/enumerable.rb:205
Array#each at kernel/bootstrap/array.rb:71
@emk
emk / 0001-Inliner-inline_ffi-Add-missing-break-statements-to-s.patch
Created November 29, 2010 20:56
Strange output from -Xjit.dump_code=7
From 87abff6f791a5a9b722bd8f84fe79fa12675969b Mon Sep 17 00:00:00 2001
From: Eric Kidd <[email protected]>
Date: Tue, 30 Nov 2010 10:39:17 -0500
Subject: [PATCH] Inliner::inline_ffi: Add missing break statements to switch
When passing doubles to FFI functions, the VM was generating spurious
calls to rbx_ffi_to_int64 follwing the expected calls to
rbx_ffi_to_double. These calls to rbx_ffi_to_int64 failed, triggering
calls to rbx_continue_uncommon and thus eventual deoptimization.