Skip to content

Instantly share code, notes, and snippets.

View bcg's full-sized avatar

Brenden Grace bcg

View GitHub Profile
@bcg
bcg / client.js
Created April 6, 2011 22:45
Node + ZeroMQ + Redis
var zmq = require('zeromq');
s = zmq.createSocket('push');
s.connect('tcp://127.0.0.1:15000');
while (true) { // ZOMG he did it again!
s.send(new Buffer("test"));
}
@bcg
bcg / resuls
Created April 7, 2011 14:21
Hipster C + ZeroMQ + Redis MQ
zmqd.c = 45k rps
@bcg
bcg / nodeunit-httputil_test.js
Created April 14, 2011 22:31
An example of nodeunit + httputil + sinon
var sys = require('sys'),
nodeUnit = require('nodeunit'),
httputil = nodeUnit.utils.httputil,
sinon = require('sinon'),
logger = require('ain-tcp');
module.exports = nodeUnit.testCase({
setUp: function(callback) {
router = require('router').router; // using choreographer
@bcg
bcg / example.rb
Created April 21, 2011 16:22
Map reduce unit tests for hadoop
#!/usr/bin/env ruby
require './rubydoop'
HADOOP_HOME = '/usr/local/Cellar/hadoop/0.21.0/libexec/'
map do |location, line|
line.split(/\s+/).each do |word|
next unless word.strip.length > 0
emit word.strip.downcase.gsub(/^\(|[^a-zA-Z]$/, ''), location
@bcg
bcg / RESULTS
Created April 25, 2011 22:23
Set Intersection Comparisons
# SCALA
[info] Loaded set in 112.9
[info] Loaded set in 7.873
[info] 9999999 intersects in 9.156
# Node.js
10000000 inserted in 16
10000000 matched in 8
@bcg
bcg / myreducer.scala
Created April 27, 2011 16:18
Problems with scala
class MyReducer extends Reducer[Text, Text, Text, Text] {
// How does one define a class level variable in Scala? Below does not work ...
var mo: MultipleOutputs[Context]
def setup(context : Context) {
mo = new MultipleOutputs(context)
}
def reduce(key : Text, values : java.util.Iterator[Text], context : Context) {
# Compile the module
~/src/riak_function_contrib/other/erlang# /usr/lib/riak/erts-5.7.5/bin/erlc bucket_importer.erl
# Move the module
~/src/riak_function_contrib/other/erlang# mv bucket_importer.beam /tmp/
~/src/riak_function_contrib/other/erlang# riak attach
# riak attach
Attempting to restart script through sudo -u riak
Attaching to /tmp/riak/erlang.pipe.1 (^D to exit)
@bcg
bcg / riak-importer.rb
Created June 27, 2011 18:25
Trivial JSON Riak Importer
require 'riak'
@host = ARGV[0]
@port = ARGV[1].to_i
@bucket = ARGV[2]
@dir = ARGV[3]
@riak_client = Riak::Client.new(:host => @host, :http_port => @port)
@riak_bucket = @riak_client.bucket(@bucket)
var fs = require('fs'),
router = require('choreographer').router();
Conductor = function() {
this.router = router;
this.services = [];
this.controllers = [];
this.requireEach('controllers', function(name, r) {
controller = new r.Controller(options);
this.addController(name, controller);
@bcg
bcg / em-loop.rb
Created September 1, 2011 12:54
EM Loop
items = [1,2,3]
(looper = proc {
item = items.pop
if item
...
EM.next_tick(looper)
end
}).call