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 / weaselSteps.js
Created October 22, 2012 13:42
for example - encapsulate callback in this context with step
var step = require("step");
var weasel1 = function(callback) {
callback(null, 'first');
}
var weasel2 = function(callback) {
callback(null, 'second');
}
@MikeBild
MikeBild / SimpleRxTesting.cs
Created October 24, 2012 17:23
Simple Rx Testing without Mocks
var expected = new long[] {0, 1, 2, 3, 4};
var actual = new List<long>();
var scheduler = new TestScheduler();
var interval = Observable.Interval(TimeSpan.FromSeconds(1), scheduler).Take(5);
interval.Subscribe(actual.Add);
scheduler.Start();
CollectionAssert.AreEqual(expected, actual);
@MikeBild
MikeBild / thelastoneturnslightoff.cs
Created November 11, 2012 17:15
Shared resource management with Rx
public class SharedResource : IDisposable
{
public int SequenceNumber { get; private set; }
public SharedResource()
{
Debug.WriteLine("SharedResource created.");
}
public void Increment()
@MikeBild
MikeBild / LRUObservableCollection.cs
Created November 13, 2012 15:18
Tiny LRU cache implementation
public class LRUObservableCollection<T> : ObservableCollection<T>
{
private readonly int _length;
public LRUObservableCollection(int length)
{
_length = length;
}
protected override void InsertItem(int index, T item)
@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();