Skip to content

Instantly share code, notes, and snippets.

View hermanbanken's full-sized avatar
🇳🇱

Herman hermanbanken

🇳🇱
View GitHub Profile

Keybase proof

I hereby claim:

  • I am hermanbanken on github.
  • I am hermanbanken (https://keybase.io/hermanbanken) on keybase.
  • I have a public key ASBjLbD1MTjXXM6g2laBrCbIwdFtH4su3dKPB3cAozB3vgo

To claim this, I am signing this object:

@hermanbanken
hermanbanken / index.html
Last active July 1, 2016 15:41
Difficulties with implicit syntax #3
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.1.0/rx.all.min.js"></script>
@hermanbanken
hermanbanken / index.html
Last active July 1, 2016 16:11
Difficulties with implicit syntax #2
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdn.rawgit.com/hermanbanken/f1af739c111f2f918406026705f53761/raw/c22eddb2c36c01a51c66740cf674093ba4bf8729/meteor-reactive-packages.js"></script>
<script>
var energyUse = ReactiveVar(0);
var energyAccumulate = ReactiveVar(0);
Tracker.autorun(() => {
// Do not register dependency on energyAccumulate
var prev = Tracker.nonreactive(() => energyAccumulate.get());
// Registering dependency on energyUse
energyAccumulate.set(prev + energyUse.get());
@hermanbanken
hermanbanken / index.html
Last active July 1, 2016 16:24
Difficulties with implicit syntax #1
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdn.rawgit.com/hermanbanken/f1af739c111f2f918406026705f53761/raw/c22eddb2c36c01a51c66740cf674093ba4bf8729/meteor-reactive-packages.js"></script>
/* This file contains 5 core meteor packages
* Base64
* EJSON
* Tracker (formerly Deps)
* ReactiveDict
* ReactiveVar
* mrt:reactive-object
* http://stackoverflow.com/a/26996309/552203
* Copyright: Dean Radcliffe
*/
@hermanbanken
hermanbanken / scaling.js
Last active July 29, 2016 11:29
Disposing and switching inner observables
'use strict';
var Rx = require("rx")
var test = require("qunitjs").test
/** stupid RxJS testing code **/
function createMessage(expected, actual) {
return ['Expected: [' + expected.toString() + "]", "Actual: [" + actual.toString() + ']'];
}
@hermanbanken
hermanbanken / rx.split.js
Created August 17, 2016 12:40
Using 1 observable, subscribe once and do two things
let observable: Observable<Bool>
////////// A
return observable.publish(obs =>
Observable.merge(
obs.filter(v => v).doOnNext(":)"),
obs.filter(v =>!v).doOnNext(":(")
)
)
@hermanbanken
hermanbanken / RxLifecycle.md
Last active September 28, 2017 18:10
RxLifecycle

Adds 6 Observable fields on UIViewController:

Two main Observable<Bool>

  • rx_visible: did the controller appear/disappear?
  • rx_willBeVisible: will the controller appear/disappear?

And conveniently splitting those two out into Observable<Void>:

  • rx_willAppear
  • rx_willDisappear
  • rx_appear
@hermanbanken
hermanbanken / ShareReplayLatestWhileNext.kt
Last active August 26, 2016 13:04
Reactive Extensions RxJava/RxKotlin ShareReplayLatestWhileNext implementation. It differs from shareReplay and shareReplayLatestWhileConnected, as explained in the comment above the method.
package com.example.rx
import rx.Observable
import rx.Subscriber
/**
* Warning: these extensions do not do any synchronization so no thread-safety guarantees!
* Implication of this is that subscribers that did dispose on another thread could still receive values.
* As long as these are synchronizing themselves everything is OK.
*
@hermanbanken
hermanbanken / rx-debug.js
Last active September 27, 2016 17:36
Rx Debug, `.debug` operator for RxJS
import Rx from 'rx';
// ES6 source, compile with babel
// Usage:
// import hook from 'rx-debug'
// hook()
// Then:
// Observable.just(1).debug("your tag")
// You will observe subscriptions, nexts, error and completion.