Skip to content

Instantly share code, notes, and snippets.

View goosmurf's full-sized avatar

Yun Huang Yong goosmurf

View GitHub Profile
#!/usr/bin/env ruby
require 'rubygems'
require 'beanstalk-client'
require 'pp'
require 'digest/md5'
beanstalk = Beanstalk::Connection.new('127.0.0.1:11300')
while true do
job = beanstalk.reserve
describe "test" do
it "should return and then raise error" do
mock = mock("Test")
crazy = 0
mock.should_receive(:blah).twice do
if crazy > 0
raise StandardError
end
crazy += 1
end
class Test
def blah
"woohoo!"
end
end
describe "count received but return normal value" do
it "should return its normal value" do
t = Test.new
t.should_receive(:blah)
describe "playing with blocks" do
it "should check the block" do
log_mock = mock("Logger")
log_mock.should_receive(:something) { |*args| puts args.size }
log_mock.something { "blah" }
end
end
module LionO
class Test
end
describe Test do
def myclass
self.class
end
it "should print the class" do
#!/usr/bin/env ruby
f = File.open("test.file", "w")
f.write("blah\n")
f = nil
#ObjectSpace.garbage_collect
puts File.readlines("test.file")
Copyright (c) 2005-2007 Thomas Uehlinger
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
#!/usr/bin/env ruby
require 'pp'
require 'rubygems'
require 'mongo'
db = XGen::Mongo::Driver::Mongo.new("localhost").db("test")
original = db.collection("original")
original.remove
original.insert( { "test" => 1 } )
#!/usr/bin/env ruby
require 'rubygems'
require 'beanstalk-client'
JOB_SIZE = 64000
beanstalk = Beanstalk::Connection.new('127.0.0.1:11300')
job_data = 'x' * JOB_SIZE
> db.t.remove()
> db.t.insert( { players: [ {player_name: "m", player_position: 3}, {player_name: "blah", player_position: 3} ] } )
> db.t.insert( { players: [ {player_name: "another", player_position: 3}, {player_name: "m", player_position: 5} ] } )
> db.t.find( { "players": { player_name: "m", "player_position": 3 }} )
{ "_id" : ObjectId("4b4eaf902976dc62f4b0f9de"), "players" : [
{
"player_name" : "m",
"player_position" : 3
},
{