Skip to content

Instantly share code, notes, and snippets.

View stuf's full-sized avatar

Stef stuf

View GitHub Profile
@stuf
stuf / SketchSystems.spec
Last active February 25, 2021 14:02
API call Promise
API call Promise
Pending
on data -> Fulfilled
on error -> Rejected
canceled -> Rejected
Fulfilled
done -> Finally
Rejected
done -> Finally
Finally
@stuf
stuf / SketchSystems.spec
Created January 15, 2020 08:40
Notification
Notification
Idle
show -> Show
Show
delay ms -> Close
Close
completed -> Reset
const { Suite } = require('benchmark');
const R = require('ramda');
const util = require('util');
const suite = new Suite();
const colors = `be4a2f
d77643
ead4aa
e4a672
Services*
Init*
init -> Get Results
Get Results
success -> Show Results
failed -> Show Error
Show Results
export declare type Lens = string | number;
export declare type Optic = Lens | Array<Lens>;
export type Pred<T> = (x: T) => boolean;
export type GetValueFn<T = any, U = T> = (maybeData: T, index: number) => U;
export type SetValueFn<T1 = any, T2 = T1, U = T2> = (maybeValue: T1, maybeData: T2, index: number) => U;
export type ModifyFn<T = any, U = T> = (maybeData: T, i?: number) => U;
@stuf
stuf / README.md
Created March 21, 2018 13:58
TSX component scaffold

TSX component scaffold

For convenience and example for whoever might be wondering about TypeScript and React.

Why separate import of SFC?

Because SFC<Props> is much more readable in a chunk of code than React.SFC<Props>

Why a separate type declarations file?

[*.js]
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
insert_final_newline = true
const $ = require('sanctuary-def');
const Ratio =
$.NullaryType('package-name/Ratio',
'https://package.url.io/Ratio',
x => typeof x === 'number' && (x >= 0 && x <= 1));
//
const def = $.create({
@stuf
stuf / iso.js
Created January 15, 2018 10:06
Isomorphisms with partial lenses for consuming OBS WebSocket data
import * as R from 'ramda';
import * as L from 'partial.lenses';
//
const splitCamelCase = R.match(/(^[a-z]+|[A-Z][a-z]+)/g);
const flatJoin = R.compose(R.join(''), R.flatten);
//
/**
* Takes a list of elements and functions (`vfn` and `kfn`) for transforming the string.
* The resulting elements from applying each function will become the `key` and `value` in
* the resulting object.
*
* For example:
*
* ```js
* const tokens = ['foo-bar', 'top-kek'];
* const Obj = foldTokens_(tokens, R.split('-'), R.toUpper);