Skip to content

Instantly share code, notes, and snippets.

@bmavity
bmavity / company-wallet.gif
Last active May 8, 2017 18:52
iota-upload-poc tutorial
company-wallet.gif
@bmavity
bmavity / gist:e4f4031a569de04c1ef5
Last active August 29, 2015 14:23
Event Store Subscription
var ges = require('ges-client')
, connection = ges()
, shouldSetMetadata = false
connection.on('connect', function() {
function setMetadata(done) {
var setData = {
expectedMetastreamVersion: ges.expectedVersion.emptyStream
, metadata: ges.createStreamMetadata({
acl: {
@bmavity
bmavity / gist:1150f53e0239a283353c
Last active August 29, 2015 14:21
Aggregate Mixin
function asAggregate() {
this.applyChange = function(evt, eventName, isFromHistory) {
var aggregate = this
var handler = aggregate[eventName]
if(handler) {
handler.call(aggregate, evt)
}

a Stream spec

This document defines the behaviour that a Stream must implement in order to be compatible with Stream#pipe. This is not an official document, but is intended as a guide to produce correct behaviour in user-land streams.

Stream

All streams must emit 'error' if writing to or reading from becomes physically impossible. 'error' implys that the stream has ended.

All streams may emit 'close'. 'close' means that any underlying resources have been disposed of. If a ReadableStream has ended normally, it must not emit 'close' before 'end'.

@bmavity
bmavity / Dispatcher.cs
Created November 10, 2011 22:02
Publishing
public void Dispatch(Commit commit)
{
var bus = _container.Resolve<IServiceBus>();
var events = commit.Events.Select(x => x.Body);
var publishMe = events.ElementAt(0);
Console.WriteLine("Publishing: " + publishMe.GetType().Name);
bus.Publish(publishMe); // doesn't work
bus.Publish(publishMe as MyMessage); // works
}
// assumes that the title content is lowercase.
// I'm aware of the duplication of some functionality.
// this is just a POC for the work I'm doing on ccs. :)
$(function() {
var $allSessions = $('#content .show'),
elementsAndTitles = $.map($allSessions, function(sessionElement) {
var $session = $('h3 a', sessionElement);
return {
$session: $session,
// readFile.js
// Load the built in file system module
var fs = require('fs');
// Read the config file (sychronously)
var rawConfig = fs.readFileSync(__dirname + '/config.json', 'utf8');
// Convert the file contents to JSON
var config = JSON.parse(rawConfig);
var outsideFunctionWithVar = 2;
(function() {
insideFunctionWithoutVar = 'hippo';
var insideFunctionWithVar = 'not defined outside of function';
})();
var ext = require('./sampleExternal');
// In node.js, there is a global object called
// global (go figure)
console.log(global); // empty object
// This is defined in the external JavaScript file
// outside of a function, and with the var keyword
console.log(global.outsideFunctionWithVar); // undefined
console.log(ext.outsideFunctionWithVar); // undefined
var outsideFunctionWithVar = 2;
(function() {
insideFunctionWithoutVar = 'hippo';
var insideFunctionWithVar = 'not defined outside of function';
})();