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 / 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 = [{
import { stateShape } from '../store'
type ClientOrdersProps = {
orders: number[],
id: number,
}
const ClientOrders = ({ orders, id }: ClientOrdersProps) =>
<div>
{orders.map( order => <div>{order}</div> )}
@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 / curry3.js
Created November 29, 2017 05:05
Flow curry3
//@flow
declare export function curry3<A, B, C, D>(fn: (a: A, b: B, c: C) => D): (
& ((a: A, nob: void, noc: void) => (
& ((b: B, noc: void) => ((c: C) => D))
& ((b: B, c: C) => D)
))
& ((a: A, b: B, noc: void) => ((c: C) => D))
& ((a: A, b: B, c: C) => D)
)
@zerobias
zerobias / .babelrc.js
Created December 10, 2017 22:19
Node.js microservice as single file w/o dependencies with babel 7 and rollup
//@flow
module.exports = {
"presets": [
"@babel/preset-flow",
["@babel/preset-env", {
"targets": {
"node": "8.9"
},
// "shippedProposals": true,
@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-ignore.js
Last active June 20, 2018 06:27
Make flow ignore all unrelated deps and work much faster
//@flow
const {
readdirSync,
outputFileSync,
pathExistsSync,
//$todo
readFileSync,
} = require('fs-extra')