Skip to content

Instantly share code, notes, and snippets.

View zerobias's full-sized avatar
💭
Set your status

Dmitry zerobias

💭
Set your status
View GitHub Profile
@zerobias
zerobias / transerfable-feature-detection.js
Created September 14, 2017 22:57
Web worker transferable object: feature detection
var ab = new ArrayBuffer(1);
worker.postMessage(ab, [ab]);
if (ab.byteLength) {
alert('Transferables are not supported in your browser!');
} else {
// Transferables are supported.
}
@zerobias
zerobias / plugins.txt
Created September 19, 2017 10:57
VS Code plugins
'addDocComments',
'annotator',
'babelrc',
'Bookmarks',
'bracket-pair-colorizer',
'code-navigation',
'code-settings-sync',
'color-highlight',
'copy-syntax',
'dark-plus-material',
@zerobias
zerobias / Type-checkable-typeclasses.js
Created November 12, 2017 04:31
Typecheckable typeclasses in flow
//@flow
type Func</*::-*/I, /*::+*/O> = (x: I) => O
type Refiner<T, P/*::: $Pred<1>*/> = (val: mixed) => $Refine<T, P, 1>
function refineType<T, P/*::: $Pred<1>*/>(cb: P): Refiner<T, P> {
return function refiner(val: mixed): $Refine<T, P, 1> {
if (cb(val)) return val
throw new TypeError()
}
@zerobias
zerobias / maybe-private.js
Last active November 24, 2017 19:26
Minimal maybe example
/**
* Example with no .value in instances. Its can be much slower,
* but if you prefer pureness, that is your choice
*/
export const just = data => new Just( data )
export const of = just
export const nothing = () => new Nothing
@zerobias
zerobias / flatten.js
Created October 13, 2017 21:17
Flow flatten type
declare function flatten<
A,
B: $ReadOnlyArray<A> | A,
C: $ReadOnlyArray<B> | B,
D: $ReadOnlyArray<C> | C,
E: $ReadOnlyArray<D> | D,
>(xs: $ReadOnlyArray<E>): Array<A>
const listsList = [{
@zerobias
zerobias / globals.d.ts
Created December 24, 2017 05:29
VS Code helpers for flowtype (yes)
declare global {
type $Shape<T> = T
type $Exact<T> = T
type $Spread<A, B> = A & B
type $ReadOnlyArray<T> = Array<T>
type $NonMaybeType<T> = T
type $Subtype<T> = T
type $Supertype<T> = T
type empty = never
type mixed = any
@zerobias
zerobias / flow-path-function.js
Created December 28, 2017 00:07
Infinite nested property lookup in flow
//@flow
declare function deepSeq<P>(
...path: P
): $TupleMap<P, <T, Prop>(prop: Prop) => T => $ElementType<T, Prop>>
declare var pipe: $ComposeReverse
const target: 'target' = 'target'
@zerobias
zerobias / do-notation.js
Created January 2, 2018 09:12
Do notation in js
export function Do(generatorFunction) {
const generator = generatorFunction()
return function next(error, v) {
const res = generator.next(v)
if (res.done)
return res.value
else
@zerobias
zerobias / effector.js
Last active January 18, 2018 21:15
Effector cheatsheet
import {Stream, fromPromise} from 'most'
import {message, effect, Effect, Message} from 'effector'
type State = {
currentUser: number,
}
/**
* Plain async function
*/
@zerobias
zerobias / most.js
Created January 24, 2018 06:54
most flow typings
//@flow
export type SeedValue<S, V> = {
seed: S,
value: V,
}
export type TimeValue<V> = {
/*::+*/time: number,
/*::+*/value: V
}