Skip to content

Instantly share code, notes, and snippets.

Mattias Petter Johansson mpj

Block or report user

Report or block mpj

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
We couldn’t find that file to show.
mpj / gist:8906631
Created Feb 9, 2014
start of a bus
View gist:8906631
var createBus = function() {
var me = {}
var _handlers = {}
var _events = [] = function(name) {
return {
on: function(address) {
return {
View gist:bc1af0ae69e3af1f22b9
### Keybase proof
I hereby claim:
* I am mpj on github.
* I am mpj ( on keybase.
* I have a public key whose fingerprint is 882A BDDF DAC0 B6CB 5EB3 078A 9BE9 D285 0A78 B179
To claim this, I am signing this object:
View gist:6d0ac52212a5da3da1e6
var findToArray = function(collection, query) {
var deferred = Q.defer();
var cursor = collection.find(query);
collection.find({}).toArray(function(error, result) {
if (error)

Snurra Broker

Snurra Broker is a message bus with a stream interface. Below is an example on how to interact with it. Snurra plays very nicely with libraries like highland.js (, but Snurra Broker does not depend on it - snurra creates plain vanilla node streams, and will work with any stream library.

_ = require 'highland'
Broker = require 'snurra-broker'
broker = new Broker()

# Calling the broker with a string (a channel name), creates a 
View gist:7fd7f209c8d77f664215
orderStream = broker('orders')
unhandledOrdersStream =
_(broker('orders')).filter (order) -> not order.shippingdate
unhandledOrdersStream.each (order) ->
# do stuff with order that is not handled

Snurra - the streaming message bus.

Snurra is a fresh take on message bus pattern by using streams as the interface instead of the more traditional callback pattern.

Snurra syntax

Let's walk through the basic syntax of Snurra.

var _ = require('highland');
var snurra = require('snurra');
var bus = snurra();
mpj / gist:1b6ad55599497340e3c1
Last active Aug 29, 2015
snurra philisophy sketch
View gist:1b6ad55599497340e3c1

1. Inspection and Simulation

The primary ambition of Snurra is to make it easier to see what is happening inside your program, mock external dependencies and to verify behavior.

2. Usability over correctness

Snurra tries looks upon the API consumer like a user, rather than a developer that can be expected to fiddle around with unclear interfaces and vague documentation.

3. No magic and no veils

Snurra tries to expose vanilla node streams as cleanly as possible and not abstract them away from the user, so that the user can take advantage of node stream documentation and stream manipulation libraries like highland.js. It is willing to sacrifice being terse or hand-holding in order to be understandable and re-usable.

4. Focus on the message

View gist:58ee72609030adca7020
WebSocket = require 'ws'
_ = require 'highland'
isNumber = require 'mout/lang/isNumber'
listen = (account) ->
stream = _()
ws = new WebSocket('ws://');
ws.on 'open', ->
payload = JSON.stringify
"command" : "subscribe"
You can’t perform that action at this time.