Skip to content

Instantly share code, notes, and snippets.

View rjhilgefort's full-sized avatar

Rob Hilgefort rjhilgefort

View GitHub Profile
const isNegative = (num) => Math.sign(num) === -1
const isPositive = (num) => Math.sign(num) === 1 || Math.sign(num) === 0
const offsetString_from_number = (data) => {
const data_ = Math.abs(data).toString().padStart(2, '0').concat(':').padEnd(5, '0')
return isNegative(data) ? `-${data_}` : `+${data_}`
}
offsetString_from_number(-5)
offsetString_from_number(+5)
export const poop =
({ prismaClient }: { prismaClient: PrismaClient }) =>
<T extends Prisma.IncidentFindManyArgs>(
slackChannelId: ChannelId,
args?: Prisma.SelectSubset<T, Prisma.IncidentFindManyArgs>,
) => {
const args_ = { ...args, where: { slackChannelId } } as Prisma.SelectSubset<
T,
Prisma.IncidentFindManyArgs
>
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)
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,
)
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)
// 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]) {
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
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,
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 17:30
Example of vanilla JS to Ramda (Reason in Notion)
const { log, clear } = console
clear()
const logHof = (fn) => (...args) => pipe(
tap(() => log('-----------------------------')),
tap((args) => log(`args: ${args}`)),
fn,
tap((res) => log(`res: ${res}`)),
)(...args)