Skip to content

Instantly share code, notes, and snippets.

View rkichenama's full-sized avatar

Richard Kichenama rkichenama

View GitHub Profile
@rkichenama
rkichenama / machine.js
Created February 7, 2023 19:48
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@rkichenama
rkichenama / Coverage Badges
Last active January 2, 2023 11:01
Coverage Badges
Coverage Badges
@rkichenama
rkichenama / calculations.js
Last active November 20, 2020 14:22
House Representative Leanings
const NormDist = (avg, stdev) => {
const { E, sqrt } = Math;
const variance = stdev ** 2;
const stdevTau = stdev * sqrt(2 * Math.PI);
const doubleVariance = 2 * variance;
return (x) => {
const distFromAvg = (x - avg) ** 2;
return (
(E ** -(distFromAvg / doubleVariance)) / stdevTau
@rkichenama
rkichenama / union.js
Last active April 18, 2018 14:16
an example of unions in javascript
// the actual union function
const union = types => types.reduce((prev, type) => ({
...prev,
[type]: data => ({
match: fns => fns[type](data),
})
}), {});
const kinds = [
@rkichenama
rkichenama / functions.js
Created February 8, 2017 17:46
Some ES6-ish functions that are kind of useful
/* assumes 1 value in, 1 value out */
const reducing = (dir = 'reduce') => (...funcs) => (value) => funcs[dir](
(v, fn) => fn(v),
value
);
const compose = reducing('reduceRight');
const pipe = reducing();
const tap = fn => value => { fn(value); return value; };
@rkichenama
rkichenama / destructuring.js
Created March 5, 2016 21:17 — forked from mikaelbr/destructuring.js
Several demos and usages for ES6 destructuring.
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => {
return [1, 2, 3];
@rkichenama
rkichenama / proxy.js
Created December 18, 2015 14:56 — forked from nadeesha/proxy.js
Node-based http/https proxy to forego the pain of configuring iptables for one-off dev tasks. Not recommended to be used in prod environments.
var fs = require('fs'),
http = require('http'),
https = require('https'),
httpProxy = require('http-proxy');
var isHttps = true; // do you want a https proxy?
var options = {
https: {
key: fs.readFileSync('key.pem'),
@rkichenama
rkichenama / SassMeister-input.scss
Created September 4, 2014 19:58
Generated by SassMeister.com.
// ----
// Sass (v3.4.1)
// Compass (v1.0.1)
// ----
$bgColor: #333;
::selection {
background: $bgColor;
color: #fff;
//-------------------------------------------------------------
//
// Hypothesis:
//
// Promises/A is a Monad
//
// To be a Monad, it must provide at least:
// - A unit (aka return or mreturn) operation that creates a corresponding
// monadic value from a non-monadic value.
// - A bind operation that applies a function to a monadic value