Skip to content

Instantly share code, notes, and snippets.

View whiteinge's full-sized avatar

Nathaniel Whiteinge whiteinge

View GitHub Profile
@whiteinge
whiteinge / micro_fp.js
Last active December 12, 2025 23:10
A bare-bones minimal (and probably slightly incorrect) implementation of Maybe, Either, IO, and Task
class Box {
constructor(x) { this._x = x }
map(f) { return new Box(f(this._x)) }
}
class LazyBox {
constructor(g) { this.g = g }
map(f) { return new LazyBox(() => f(this.g())) }
}
@whiteinge
whiteinge / waitlatestfrom.js
Created March 21, 2017 17:07
waitLatestFrom RxJS operator as a middle-ground between withLatestFrom and combineLatest
/**
waitLatestFrom(...sources, [selector])
Like withLatestFrom but waits for all sources to produce at least one value
before emitting. Emits immediately once it has a value for all sources. After
that it actively collects the latest emission from the other source observables
in the background and emits the latest collected values whenever the primary
source emits -- like withLatestFrom.
If the primary source completes, the other sources will be completed as well.
@whiteinge
whiteinge / validate.py
Created October 25, 2016 16:14
CLI tool to validate a Voluptuous schema (can be used as a pre-commit hook)
#!/usr/bin/env python
# coding: utf-8
'''
Validate input file(s) against a Voluptuous schema
Pass a dash to read from stdin.
'''
from __future__ import print_function
import imp
@whiteinge
whiteinge / rxjs-poller-with-backoff.js
Last active April 1, 2021 23:52
An RxJS poller with incremental back-off as a let-function
import { TimeoutError, timer } from 'rxjs'
import { AjaxTimeoutError } from 'rxjs/ajax'
import {
delay,
filter,
flatMap,
repeatWhen,
retryWhen,
scan,
timeout,
@whiteinge
whiteinge / myapp.sls
Last active August 12, 2017 00:22
Prereq example for optionally draining Apache before updating a web app
include:
- git
apache:
pkg.installed:
- name: httpd
service.running:
- name: httpd
- enable: True
@whiteinge
whiteinge / flux-with-vanilla-rx.js
Last active July 27, 2023 10:36
An example of canonical Flux using vanilla RxJS
var Actions = new Rx.Subject();
Actions.onCompleted = () => {}; // never complete
var act = (tag, data = {}) => ({tag, data});
var send = tag => data => Actions.onNext(act(tag, data));
var Dispatcher = Actions.asObservable();
// ----------------------------------------------------------------------------
var C = constants = {
GET_USER: 'get_user',
@whiteinge
whiteinge / rxjs-flux-utils.js
Last active March 22, 2016 03:33
Misc collection of shorthand helper functions for Flux implemented with Rx
/**
Misc collection of shorthand helper functions for Flux implemented with Rx
**/
import Rx from 'rx';
import _ from 'lodash';
import formSerialize from 'form-serialize';
Rx.Observable.prototype.byTag = byTag;
@whiteinge
whiteinge / rxjs-spinner-poc.js
Created March 2, 2016 05:56
Render a spinner while waiting for an ajax response using RxJS
// Central xhr progress tracker. Used for both a global
// activity indicator as well as granular spinners within in a page.
var Progress$ = new Rx.Subject();
// Make an xhr call and make a tag to track the progress ticks.
var users$ = Rx.DOM.ajax({
method: 'GET',
url: 'https://api.github.com/users',
responseType: 'json',
progressObserver: Rx.Observer.create(
@whiteinge
whiteinge / index.js
Last active September 19, 2017 03:50
POC Node HTTP server for server-sent-events using RxJS
/**
Proof-of-concept server-sent events HTTP server using Node.js and RxJS
Open http://localhost:8000 in a browser and view the console.
**/
var http = require('http'),
https = require('https');
var Rx = require('rx');
@whiteinge
whiteinge / requirements.txt
Last active October 18, 2016 02:22
Tornado worker threads plus SSE streams plus reading/writing to sqlite; this is a benchmarking POC and not useful in production!
# Only required on Python 2
futures==3.0.3
tornado==4.3