Skip to content

Instantly share code, notes, and snippets.

View MikeBild's full-sized avatar
🏠
Working from home

Mike Bild MikeBild

🏠
Working from home
View GitHub Profile
@MikeBild
MikeBild / coin-changer.js
Last active October 29, 2016 09:13
Resource lifetime binding to RxJS stream
const Rx = require('rx');
const coinsStream = Rx.Observable.fromArray([1,2,5,10,20,50,100].reverse());
Rx.Observable
// bind CoinResource lifetime to the stream lifetime
.using(() => new CoinResource(9), resource => coinsStream.map(x => ({ amount: resource.getValue(), coin: x })))
// calculations
.reduce((state, e) => {
const amount = (state.length > 0) ? state[state.length-1].rest : e.amount;
@MikeBild
MikeBild / event-sourced.js
Created October 25, 2016 16:32
Event-Source with Event-Log persistence with RxJS
const fs = require('fs');
const Rx = require('rx');
const RxNode = require('rx-node');
const timerStream = new Rx.Subject();
const initialState = {count: 0};
const updateState = (state, msg) => {
state.count++;
return state;
};
@MikeBild
MikeBild / cpu-bound.js
Last active October 25, 2016 14:12
Node.js - CPU bound operations with Rx
const RxNode = require('rx-node');
const Rx = require('rx');
const spawn = require('child_process').spawn;
RxNode.fromStream(spawn('find', ['/','-type','f','-exec', 'cat', '{}', '\+']).stdout)
.map(x => x.toString())
// using python
.map(x => RxNode.fromStream(spawn('./word-count.py', [x]).stdout))
// or using javascript
//.map(x => RxNode.fromStream(spawn('./word-count.js', [x]).stdout))
@MikeBild
MikeBild / archive.tpl-ejs.html
Last active December 30, 2015 07:23
mikebild.com
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>Mike Bild - Archive</title>
<link rel="stylesheet" href="mikebild.css" type="text/css" />
<link rel="stylesheet" href="pygment_trac.css" type="text/css" />
@MikeBild
MikeBild / order-line.task.js
Last active December 12, 2015 14:39
Order Line API
const request = require('request-promise');
state.orders = state.orders || [];
this.GET = getOrders;
this.POST = startOrderProcess;
this.DELETE = abortOrder;
if(!this[req.method]) return res.status(404).end();
this[req.method](req.params, req.body);
@MikeBild
MikeBild / microservice-workflows.md
Last active November 1, 2016 17:11
Microservice Workflows mit Consumer-Driven-Contracts

Microservice Workflows mit Consumer-Driven-Contracts

Allen voran geht es mir um die Vereinfachung der Softwareentwicklung auch auf Systemebene. Ich meine die folgenden Artikel zeigen zumindest mittel- und langfristig genau das Gegenteil und sind ein gutes Beispiel ausufernder Systemlandschaften durch selbstverschuldet aufgesetzte Komplexität.

Wer Microservice richtig richtig macht, braucht keine Workflow Engine, kein BPMN, kein ESB, kein Message Broker, keine Aktor-Modelle und Frameworks, keine Enterprise Application Server, kein Event-Sourcin

/* empty */
@MikeBild
MikeBild / async-either-with-promise.js
Last active November 10, 2018 15:40
Async Railway Oriented Programming in JS
#!/bin/env node
//thx to http://fsprojects.github.io/Chessie/a-tale-of-3-nightclubs.html
Promise.all([
suitablePersonEnterGayBar(),
unsuitablePersonEnterGayBar(),
])
.then(result => result.map((person, i) => `Person ${i+1}: ${person.cost || ''}${person.reasons.join(' ')}`))
.then(result => console.log(`Person entries\n${result.join('\n')}`));
/*
# jquery.couch.longpoll.js #
A handler that can be used to listen to changes from a CouchDB database,
using long-polling.
This seemed to be a bit simpler than using continuous polling, which I
was unable to get working with jQuery.
@MikeBild
MikeBild / gist:031e88dd5af0d5c9f9b2
Created January 8, 2015 08:54
Mocha integration tests example
'use strict';
var assert = require('assert'),
restify = require('restify');
var client = restify.createJsonClient({
version: '*',
rejectUnauthorized: false,
url: 'https://127.0.0.1:8080',
headers: {'x-auth-token':'66LOHAiB8Zeod1bAeLYW'}