Skip to content

Instantly share code, notes, and snippets.

// https://github.com/microsoft/TypeScript/issues/13298#issuecomment-885980381
type UnionToIntersection<U> = (
U extends never ? never : (arg: U) => never
) extends (arg: infer I) => void
? I
: never;
type UnionToTuple<T> = UnionToIntersection<
T extends never ? never : (t: T) => T
> extends (_: never) => infer W
type Ix = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
type KVMap<T extends { k: string, v: any }> = {
[k in T['k']]: Extract<T, { k: k }>['v']
}
type ZipKVMap<K extends string[], V extends any[]> = {
[ix in Ix]
: K[ix] extends string
? V[ix] extends infer T
@gabiseabra
gabiseabra / Stack.hs
Last active July 21, 2021 01:18
typeclass for unstacking of adts
{-# LANGUAGE
TypeFamilies
, FlexibleInstances
, UndecidableInstances
, FunctionalDependencies
#-}
module Garbage where
data Root m a = Root (m a)
@gabiseabra
gabiseabra / orbit.js
Created March 13, 2021 02:45
Orbit bits extracted from `OrbitControls` and adapted to mousemove event
import * as THREE from 'three'
/**
* @see https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/OrbitControls.js#L152
*/
export const mkOrbitControl = (canvas, options = {}) => {
const orbit = mkOrbit(canvas, options)
const pos = new THREE.Vector2()
const listener = (e) => {
import mapValues from 'lodash/mapValues'
import curry from 'lodash/curry'
import {connect} from 'react-redux'
/**
* Creates an async dispatcher for a given actionFn
* @param {Function} dispatch Redux action dispatcher
* @param {Function} actionFn Action creator, eg: (async, ...args) => ({type: "SOME_ACTION", async})
* @returns {Function} Async action dispatcher
*/