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 / 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 / flow.js
Last active December 17, 2015 20:39
playing with .bind and sequencing async apply
var Flow = function(){
this.args = Array.prototype.slice.call(arguments);
var next = function(){
if(this.args.length>0){
this.args.shift();
this.args[0].apply(next, Array.prototype.slice.call(arguments));
}
}.bind(this);
this.args[0].apply(next);
}
@MikeBild
MikeBild / es.js
Last active December 19, 2015 08:29
Tic Tac Toe - Event-Store - JavaScript
"use strict";
(function(exports){
exports.Aggregate = function(){
var events = [],
state = {};
return {
when: function(match){
state = match.$init ? match.$init : {};
for (var i = 0; i < events.length; i++) {
if(match[events[i].type] && events[i].data)
@MikeBild
MikeBild / EventAggregator.h
Last active December 19, 2015 16:19
simple Event-Aggregator using ReactiveCocoa
#import <Foundation/Foundation.h>
#import <ReactiveCocoa/ReactiveCocoa.h>
@interface EventAggregator : NSObject {
RACSubject *subject;
RACSignal *stream;
}
- (void) subscribe:(Class) type :(void (^)(id event))handler;
- (void) send:(id)event;
@end
@MikeBild
MikeBild / visitor_pattern.js
Created July 21, 2013 05:41
simple visitor pattern implementation
var calculator = {
add: function (node) {
return visit(this, node.l) + visit(this, node.r);
},
sub: function (node) {
return visit(this, node.l) - visit(this, node.r);
},
value: function (node) {
return node.value;
}
@MikeBild
MikeBild / reactive_apps.html
Created September 27, 2013 06:55
reactive applications - some examples
<!DOCTYPE HTML>
<html>
<head>
<title>Reactive Applications</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/rxjs/2.1.11/rx.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/rxjs/2.1.11/rx.aggregates.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/rxjs/2.1.18/rx.time.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/rxjs/2.1.11/rx.binding.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/rxjs-dom/2.0.7/rx.dom.min.js"></script>
</head>
@MikeBild
MikeBild / coinchanger.cs
Created October 2, 2013 04:50
Coin Changer with LINQ
var amount = 99;
(from n in new[] { 1, 2, 5, 10, 20, 50, 100 }
orderby n descending
select new { Coin = n, Number = amount / n, Spare = (amount %= n) }).Dump();
@MikeBild
MikeBild / coinchanger_without_shared_state.cs
Created October 2, 2013 09:39
Coin Changer Data hack without shared state :-/
int[] a={100,100,100,100,100,100,100};
new[]{1,2,5,10,20,50,100}.Reverse()
.Zip(a, (coin,amount)=>{ return new Dictionary<string,int>(){{"coin",coin},{"amount",amount},{"remainder",amount}};})
.Aggregate(new Dictionary<string,int>(){{"coin",100},{"amount",100},{"remainder",100}}, (acc, n) => {
acc["coins" + n["coin"]] = acc["remainder"]/n["coin"];
acc["remainder"] = acc["remainder"]%n["coin"];
return acc;
})
@MikeBild
MikeBild / reactive_coin_changer.html
Created October 2, 2013 11:23
Reactive Coin Changer
<!DOCTYPE HTML>
<html>
<head>
<title>Reactive Coin Changer</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/rxjs/2.1.11/rx.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/rxjs/2.1.11/rx.aggregates.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/rxjs/2.1.18/rx.time.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/rxjs/2.1.11/rx.binding.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/rxjs-dom/2.0.7/rx.dom.min.js"></script>
</head>
@MikeBild
MikeBild / coinchanger.js
Created October 3, 2013 06:43
Coin Changer in JS without state mutate
[1,2,5,10,20,50,100].reverse()
.reduce(function(acc, n){
return {
amount: acc.amount%n,
results: acc.results.concat({Coin:n, N: Math.floor(acc.amount/n)})
}
}, {amount:99, results:[]});