Skip to content

Instantly share code, notes, and snippets.

var spawn = require('child_process').spawn,
netBinding = process.binding('net'),
net = require('net');
// pipe
(function(){
var infds = netBinding.pipe();
var outfds = netBinding.pipe();
{
ifequal: function(chunk, context, bodies, params) {
if (params.left === params.right) {
return chunk.render(bodies.block, context);
} else {
return chunk.render(bodies['else'], context);
}
},
foo: "value",
bar: "value"
{
"helper": function(chunk, context, bodies, params) {
if (typeof params.foo === "function") {
// if params.foo is a function body, render it
return params.foo(chunk, context);
}
// otherwise just echo the string
return chunk.write(params.foo);
},
"what": "pie"
(function(uustats){
uustats.sdev = function(series) {
return Math.sqrt(uustats.variance(series));
};
uustats.variance = function(series) {
var t = 0, squares = 0, len = series.length;
for (var i=0; i<len; i++) {
MyStruct = Struct.new :name, :rating
a = MyStruct.new 'Michael', 10
b = MyStruct.new 'Jim', 9
c = MyStruct.new 'Dwight', 10
arr = [a, b, c]
arr.sort_by {|obj| [-obj.rating, obj.name]}
#!/usr/bin/env ruby
require 'mongo'
require 'mongo/gridfs'
require 'rufus/edo'
require 'benchmark'
host = ENV['MONGO_RUBY_DRIVER_HOST']
port = ENV['MONGO_RUBY_DRIVER_PORT']
require 'eventmachine'
require 'fiber'
Q = Array.new
worker = Fiber.new do
loop do
Fiber.yield
blk = Q.shift
blk.call if blk
require 'eventmachine'
require 'fiber'
def run_fiber(f)
EM.next_tick do
f.resume
if f.alive?
run_fiber(f)
end
end
module Pastiche
class SpecStore
def initialize(store)
@store = store
end
class StoreError < RuntimeError; end
module Assertion
def assert(message, &block)
unless block.call
require 'pastiche'
require 'pastiche/serializer'
require 'restclient'
module Pastiche
class RESTStore
def initialize(uri, opts={})
@uri = uri
end