This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var spawn = require('child_process').spawn, | |
| netBinding = process.binding('net'), | |
| net = require('net'); | |
| // pipe | |
| (function(){ | |
| var infds = netBinding.pipe(); | |
| var outfds = netBinding.pipe(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'eventmachine' | |
| require 'fiber' | |
| Q = Array.new | |
| worker = Fiber.new do | |
| loop do | |
| Fiber.yield | |
| blk = Q.shift | |
| blk.call if blk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'eventmachine' | |
| require 'fiber' | |
| def run_fiber(f) | |
| EM.next_tick do | |
| f.resume | |
| if f.alive? | |
| run_fiber(f) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Pastiche | |
| class SpecStore | |
| def initialize(store) | |
| @store = store | |
| end | |
| class StoreError < RuntimeError; end | |
| module Assertion | |
| def assert(message, &block) | |
| unless block.call |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'pastiche' | |
| require 'pastiche/serializer' | |
| require 'restclient' | |
| module Pastiche | |
| class RESTStore | |
| def initialize(uri, opts={}) | |
| @uri = uri | |
| end |
NewerOlder