Skip to content

Instantly share code, notes, and snippets.

View rjhilgefort's full-sized avatar

Rob Hilgefort rjhilgefort

View GitHub Profile
// validateRequired :: [String] | String a -> a | ThrownError
const validateRequired = propOrPath => R.cond([
[isString, R.compose(validateRequired, R.of)],
[R.T, path => R.when(
R.pathSatisfies(R.isNil, path),
R.compose(
fpThrow,
R.always(`"${path}" is required and must be present`),
)
)]
@rjhilgefort
rjhilgefort / is-obj-diff.js
Last active August 2, 2018 03:28
Check if objects are different, but only for white listed fields in a struct.
const { log, clear } = console;
clear()
const trace = (tag) => (x) => {
log(`\n${tag}\n==================================================`);
log(JSON.stringify(x, 0, 2));
return x;
}
// misc.js
///////////////////////////////////////////////////////////////////////////////////////
@rjhilgefort
rjhilgefort / trace.js
Created August 1, 2018 19:50
point free logger for any JS env
const { log } = console;
const trace = (tag) => (x) => {
log(`\n${tag}\n==================================================`);
log(JSON.stringify(x, 0, 2));
return x;
}
@rjhilgefort
rjhilgefort / keybase.md
Created July 30, 2018 23:26
keybase.md

Keybase proof

I hereby claim:

  • I am rjhilgefort on github.
  • I am rjhilgefort (https://keybase.io/rjhilgefort) on keybase.
  • I have a public key ASDJQfOqOlsZCq_eKVHu4Vn3-qJVIaQv3fbLXPMcQCFhawo

To claim this, I am signing this object:

@rjhilgefort
rjhilgefort / trace.js
Last active August 1, 2018 19:50
point free logger (node only because of utils)
/* eslint-disable no-console */
import * as R from 'ramda';
import util from 'util';
const inspect = R.compose(
R.flip,
R.curryN(2),
)(util.inspect);
export default x => {
@rjhilgefort
rjhilgefort / connect-four.js
Last active June 14, 2018 15:28
A quick Connect Four app build with a single class. Has a stupid AI, simulate, and user interaction. In ramda REPL: https://goo.gl/WBd2jL
const { log, clear } = console
const reduceI = addIndex(reduce);
const HUMAN = 'X';
const COMPUTER = 'O';
class Board {
constructor({
rows = 4,
const { log } = console;
console.clear();
const logHof = fn => (...args) => {
log('logHof')
log(args);
return fn(...args);
};
const incrementHof = fn => (x, y) => {
@rjhilgefort
rjhilgefort / promise-utils.js
Last active January 7, 2019 22:51
Some utils to compose promise more easily.
console.clear()
///////////////////////////////////////////////////////////////
// promise-utils.js
// PromiseAll :: Promise.all
const PromiseAll = (x) => Promise.all(x)
// thenP :: Function -> Promise -> Promise
const thenP =
@rjhilgefort
rjhilgefort / class.js
Last active December 2, 2017 19:48
Class vs Factory
class ConsecutiveFailure {
constructor({
count = 0,
threshold = 10,
logger = console.log,
}) {
this.count = count;
this.threshold = threshold;
this.logger = logger;
}
// NOTE: Ramda repl
console.clear()
const foo = (a, b) => a + b
const bar = () => 4
const tryYolo = curry((func, params) => {
try {
return apply(func, params)