Skip to content

Instantly share code, notes, and snippets.

View rjhilgefort's full-sized avatar

Rob Hilgefort rjhilgefort

View GitHub Profile
#!/usr/bin/env node
/* eslint-disable import/no-commonjs */
;(async () => {
const util = require('util')
const child_process = require('child_process')
const { tap } = require('ramda')
const execP = util.promisify(child_process.exec)
const exec = command => execP(command).then(({ stdout, stderr }) => {})
console.clear()
const upperAsync = (x) => Promise.resolve(toUpper(x))
const splitChars = split('')
const handleResponse = curry((tag, promise) =>
pipe(
then((data) => {
console.log(`${tag}-SUCCESS: ${data}`)
return data
const { log, clear } = console;
clear();
log('=================================================');
const add2 = (x, y) => x + y;
const add2P = (x, y) => Promise.resolve(x + y);
const logFn =
const logAdd2 = logFn(add2);
const { log, clear } = console
clear()
class Foo {
constructor() {
this.state = {}
this.util = {
nested: {
mergeRight,
identity,
const maybeHof = compose(when, complement)(isNil)
const maybeToUpper = maybeHof(toUpper)
maybeToUpper(null) // null
maybeToUpper(undefined) // undefined
maybeToUpper('foo') // 'FOO'
const evolveAll = spec => compose(
evolve(spec),
compose(pickAll, keys)(spec),
)
const maybeHof = compose(when, complement)(isNil)
const maybeToUpper = maybeHof(toUpper)
evolveAll({
@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),
// `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"}
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
@rjhilgefort
rjhilgefort / colorls-alias.sh
Last active February 7, 2023 16:22
https://github.com/athityakumar/colorls beautifies your `ls` and adds icons!
# Enable tab completion of flags
source $(dirname $(gem which colorls))/tab_complete.sh
# Move standard ls
alias ols="ls"
# Base formats
alias ls="colorls -A" # short, multi-line
alias ll="colorls -1A" # list, 1 per line
alias ld="ll" # ^^^, NOTE: Trying to move to this for alternate hand commands
alias la="colorls -lA" # list w/ info