Skip to content

Instantly share code, notes, and snippets.

View mpj's full-sized avatar

Mattias Petter Johansson mpj

View GitHub Profile
We couldn’t find that file to show.
@mpj
mpj / gist:808
Created July 22, 2008 10:27
undefined
@mpj
mpj / gist:8906631
Created February 9, 2014 21:59
start of a bus
View gist:8906631
var createBus = function() {
var me = {}
var _handlers = {}
var _events = []
me.space = function(name) {
return {
on: function(address) {
return {
View gist:bc1af0ae69e3af1f22b9
### Keybase proof
I hereby claim:
* I am mpj on github.
* I am mpj (https://keybase.io/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)
deferred.reject(error)
else
deferred.resolve(result)
})
View snurra-idea.md

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 (http://highlandjs.org/), 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
@mpj
mpj / snurra-api-prototype.md
Last active August 29, 2015 14:06
Snurra sketch
View snurra-api-prototype.md

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
mpj / gist:1b6ad55599497340e3c1
Last active August 29, 2015 14:06
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

@mpj
mpj / gist:58ee72609030adca7020
Created September 26, 2014 16:55
stellar-stream
View gist:58ee72609030adca7020
WebSocket = require 'ws'
_ = require 'highland'
isNumber = require 'mout/lang/isNumber'
listen = (account) ->
stream = _()
ws = new WebSocket('ws://live.stellar.org:9001');
ws.on 'open', ->
payload = JSON.stringify
"command" : "subscribe"