Skip to content

Instantly share code, notes, and snippets.

Avatar

Christophe Geers geersch

View GitHub Profile
@geersch
geersch / relay.js
Created Sep 4, 2014
tiny-router controller relays
View relay.js
var tessel = require('tessel');
var relaylib = require('relay-mono');
var router = require('tiny-router');
setTimeout( function() {
var relay = relaylib.use(tessel.port['A']);
relay.on('ready', function relayReady() {
console.log('Relays ready...');
@geersch
geersch / relay.js
Created Sep 3, 2014
Tessel: test of toggling a relay through a HTTP request
View relay.js
var tessel = require('tessel');
var relaylib = require('relay-mono');
var http = require( 'http' );
var myIP = require('my-ip');
setTimeout( function() {
var relay = relaylib.use(tessel.port['A']);
relay.on('ready', function relayReady () {
View gist:52767d440294be0a1188
public class SessionActivities : IBundle
{
private Projection<List<SessionActivity>> _projection;
public IProjection Build()
{
_projection = Compose<List<SessionActivity>>
.Projection()
.Initialize(() => new List<SessionActivity>())
.When("SessionOpened", (@event, state) =>
@geersch
geersch / gist:edd75a600e86fb59130b
Last active Aug 29, 2015
#1 - Creating a projection
View gist:edd75a600e86fb59130b
// Compose a projection.
// - Tell what type of state the projection maintains (List<WizardActivity>)
var projection = Compose<List<WizardActivity>>.Projection()
.Initialize(() => new List<WizardActivity>()) // How do you want to initialize the state when you run the projection?
// When a wizard was started we want to know about it.
.When<WizardStarted>((@event, state) =>
{
var activity = new WizardActivity(@event.CorrelationId.Value, @event.TimeStamp);
if (!state.Contains(activity))
state.Add(activity);
@geersch
geersch / angular-log4angular.js
Last active Aug 29, 2015
angular-log4angular.js
View angular-log4angular.js
(function (window, angular, undefined) {
'use strict';
var log4AngularModule = angular.module('bp.log4Angular', []).
provider('$log4Angular', $log4AngularProvider);
log4AngularModule.factory('consoleAppender', ['$log', function ($log) {
// Define the constructor function
function Appender($log) {
@geersch
geersch / gist:9502826
Last active Aug 29, 2015
SellableFactory
View gist:9502826
function sellableFactory() {
this.deserialize = function (properties) {
var factory = new window[properties.type + 'SellableFactory']();
var sellable = Object.create(factory.sellableType.prototype);
angular.copy(properties, sellable);
return sellable;
}
};
function glasscurtainSellableFactory() {
@geersch
geersch / gist:9335086
Created Mar 3, 2014
Node storing POSTs inside the Event Store
View gist:9335086
var express = require('express');
var app = express();
var http = require('http');
var uuid = require('node-uuid');
var cluster = require('cluster');
var numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
@geersch
geersch / gist:9207063
Created Feb 25, 2014
Instead of enums...
View gist:9207063
public class Error
{
public static readonly Error None = new Error("none");
public static readonly Error InternalError = new Error("E1");
// ...
protected Error(string errorCode)
{
Code = errorCode;
}
@geersch
geersch / gist:7944393
Last active Dec 31, 2015
EventStore Projections
View gist:7944393
fromStream("account-55")
.when({
$init: function (s,e) {
return { total: 0 };
},
AccountDebited: function(s, e) {
s.total += e.body.debitedAmount; // Mo money, mo problems
return s;
},
AccountCredited: function(s, e) {
@geersch
geersch / gist:7710361
Last active Mar 9, 2018
AppHarbor RequireHttpsAttribute for Web API
View gist:7710361
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
namespace AppHarbor.Web
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]