Skip to content

Instantly share code, notes, and snippets.

Avatar

Rob Hilgefort rjhilgefort

View GitHub Profile
View fluture-monet
import { tap, prop, chain, invoker, map } from 'ramda';
// https://monet.github.io/monet.js/
import { Maybe, Just, Some } from 'monet';
// https://github.com/fluture-js/Fluture
import { encaseP, fork } from 'fluture';
const { log, error } = console;
const fetchF = (...args) =>
encaseP(fetch)(...args)
View io-ts-custom-types.ts
export const NonEmptyStrT = new t.Type<string, string, unknown>(
'NonEmptyStrT',
(input): input is string => typeof input === 'string',
(input, context) =>
typeof input === 'string' &&
pipeVal(input, trim, allPass([isString, isNotEmpty]))
? right(input)
: t.failure(input, context, 'string cannot be empty'),
t.identity,
)
View evolveSpec.js
import { isArray, curry, isPlainObject, isFunction, isNil } from 'lodash/fp'
import { mapValuesWithKey } from './mapValuesWithKey'
import { mapWithKey } from './mapWithKey'
const iteratee = (spec, full) => (val, key) => fn(spec[key], val, full)
const fn = (spec, data, full) => {
if (isNil(spec)) return data
if (isFunction(spec)) return spec(full)
if (isPlainObject(spec)) return mapValuesWithKey(iteratee(spec, full), data)
View groupAnagrams.js
// input array of words - ['tea', 'eat', 'ate', 'leap', 'peak', 'foo', 'bar']
// output - [ ['eat', 'ate', 'tea'], ['foo'], {'bar'}, {'leap', 'peal'}]
const foo = (words) => {
const wordsGrouped = words.reduce(
(acc, word) => {
const sortedWord = word.split('').sort().join('')
// Make sure we have an entry for this sorted word
if (!acc[sortedWord]) {
View index.ts
import React, { FC, CSSProperties } from 'react'
import { string, number, object, shape } from 'prop-types'
import { getTheme, GetThemeProps } from '@dcf/theme'
import { baseIcons } from './iconMapping'
type P = {
icon: string
size?: number
viewBox?: string
View propTypes.js
import { curry } from 'lodash/fp'
import PropTypes, { func, shape } from 'prop-types'
const args = {
openEntity: func.isRequired,
closeEntity: func.isRequired,
gridApi: shape({
getDisplayedRowCount: func.isRequired,
isQuickFilterPresent: func.isRequired,
}).isRequired,
View csv-to-json.js
const fs = require('fs')
const path = require('path')
const _ = require('lodash')
const parser = require('csv-parse/lib/sync')
const JsonStringify = x => JSON.stringify(x, null, 2)
const SRC_DIR = path.join(__dirname, '..', 'src')
_.forEach(
@rjhilgefort
rjhilgefort / ramda.js
Last active May 1, 2019
Example of vanilla JS to Ramda (Reason in Notion)
View ramda.js
const { log, clear } = console
clear()
const logHof = (fn) => (...args) => pipe(
tap(() => log('-----------------------------')),
tap((args) => log(`args: ${args}`)),
fn,
tap((res) => log(`res: ${res}`)),
)(...args)
View cli.js
#!/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 }) => {})
View then.js
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