Skip to content

Instantly share code, notes, and snippets.

View whiteinge's full-sized avatar

Seth House whiteinge

View GitHub Profile
@whiteinge
whiteinge / index.html
Last active July 27, 2023 10:35
Use an ADT with RxJS to model a complete ajax request/response life cycle (in batches!)
<!doctype html>
<html>
<div id="content"></div>
<style>
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 20px;
}
@whiteinge
whiteinge / nodeRxXhr.js
Created February 28, 2018 07:23
Wrap Node's https.request() in an RxJS observable
var https = require('https');
var Rx = require('rx');
/**
Wrap Node's https.request() in an RxJS observable
**/
function nodeRxXhr(options, postData) {
return Rx.Observable.create(function(obs) {
var req = https.request(options, function(res) {
res.setEncoding('utf8');
@whiteinge
whiteinge / index.html
Last active July 27, 2023 10:36
GitGraph.js branching and release process example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Foo Branching</title>
<style type="text/css">
.gitgraph-tooltip {
position: absolute;
@whiteinge
whiteinge / echo.js
Created September 16, 2017 00:57
Verbose node.js websocket logging server
const express = require('express');
const http = require('http');
const url = require('url');
const WebSocket = require('ws');
const app = express();
app.use(function (req, res) {
res.send({});
});
@whiteinge
whiteinge / complex_salt_orchestrate.sls
Last active March 20, 2024 15:48
An example of a complex, multi-host Salt Orchestrate state that performs status checks as it goes
# /srv/salt/upgrade_the_app.sls
# Example of a complex, multi-host Orchestration state that performs status checks as it goes.
# Note, this is untested and is meant to serve as an example.
# Run via: salt-run state.orch upgrade_the_app pillar='{nodes: [nodeA, nodeB], version: 123}'
{% set nodes = salt.pillar.get('nodes', []) %}
{% set all_grains = salt.saltutil.runner('cache.grains',
tgt=','.join(nodes), tgt_type='list') %}
{# Default version if not given at the CLI. #}
@whiteinge
whiteinge / rx4torx5.js
Last active August 9, 2017 00:02
Convert an Rx4 Observable into an Rx5 Observable (in case you need both)
/**
Convert an Rx4 Observable into an Rx5 Observable
Usage:
// When referenced:
var o4 = Rx4.Observable.interval(500).take(2).map('from 4');
var o5 = Rx5.Observable.interval(500).take(2).mapTo('from 5');
fromRx4(o4).concat(o5).subscribe(
@whiteinge
whiteinge / micro_fp.js
Last active May 15, 2024 20:11
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,