Skip to content

Instantly share code, notes, and snippets.

View rjhilgefort's full-sized avatar

Rob Hilgefort rjhilgefort

View GitHub Profile
@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 / 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 / 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
///////////////////////////////////////////////////////////////////////////////////////
// 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`),
)
)]
const R = require('ramda')
const { Logger } = require('../logger')
// higher order "plugin" factories; these functions accept
// a factory, add functionality to it, and then return it
const locksHof = require('./locksHof')
const loggerHof = require('./methodLoggerHof')
const speakHof = require('./speakHof')
// create a "base" higher-order factory that has adds the methods
// `tryCatch` is useful when you want to do assignment and have a sane default
// The value provided is not parseable, so we get `{}` because there was an error
tryCatch(JSON.parse, always({}))('{{50')
// {}
// Here, the value is parseable, so we get the parsed object literal
tryCatch(JSON.parse, always({}))('{ "foo": "HI" }')
// {"foo": "HI"}
@rjhilgefort
rjhilgefort / pipeAny_composeAny.js
Last active December 4, 2018 21:58
`pipeAny` (`pipe` + `pipeP`) and `composeAny` (`compose` + `composeP`) allows sync and async functions mixed together in a pipeline. ramda repl: https://goo.gl/DD6jS5
console.clear()
// util.js
/////////////////////////////////////////////////////////////////
const PromiseResolve = x => Promise.resolve(x)
// pipeAny.js
/////////////////////////////////////////////////////////////////
const pipeAny = compose(
apply(pipeP),
const evolveAll = spec => compose(
evolve(spec),
compose(pickAll, keys)(spec),
)
const maybeHof = compose(when, complement)(isNil)
const maybeToUpper = maybeHof(toUpper)
evolveAll({
const maybeHof = compose(when, complement)(isNil)
const maybeToUpper = maybeHof(toUpper)
maybeToUpper(null) // null
maybeToUpper(undefined) // undefined
maybeToUpper('foo') // 'FOO'