This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// fail silently | |
type Age = "6" | "12" | "24" | "54" | "72" | "84" | |
type AgeOld = Extract<Age, "72" | "84" | "62"> | |
// fail kabum | |
type Age = "6" | "12" | "24" | "54" | "72" | "84" | |
type ExtractOrFail<T, U extends T> = U | |
type AgeOld = ExtractOrFail<Age, "72" | "84" | "62"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
umbrella: | |
https://github.com/thi-ng/umbrella/blob/develop/packages/math/src/fit.ts | |
arduino: | |
https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/WMath.cpp#L52 | |
p5: | |
https://github.com/processing/p5.js/blob/main/src/math/calculation.js#L448 | |
openframework: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useLayoutEffect, useState } from 'react'; | |
/** | |
* Determine if the input DOM element is truncated by CSS (using ellipse for example) | |
* @param domElement | |
* @returns boolean | |
*/ | |
export function isTruncated(domElement: Element): boolean { | |
// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollWidth | |
return domElement.scrollWidth > domElement.clientWidth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function mapIndexValues<Key extends string | number | symbol, ValueInput, ValueOutput>( | |
input: Record<Key, ValueInput>, | |
iteratee: (key: Key, val: ValueInput, index: number) => ValueOutput | |
): Record<Key, ValueOutput> { | |
const entries = Object.entries(input).map(([key, value], index) => [ | |
key, | |
iteratee(key as Key, value as ValueInput, index) | |
]); | |
return Object.fromEntries(entries); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dayjs = require('dayjs') | |
var minMax = require('dayjs/plugin/minMax') | |
dayjs.extend(minMax) | |
const input = [ | |
{time: '2020-07-23T11:30:00Z', value: 1}, | |
{time: '2020-07-24T11:30:00Z', value: 1}, | |
{time: '2020-07-05T11:30:00Z', value: 2}, | |
{time: '2020-07-30T11:30:00Z', value: 3}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
yarn add @thi.ng/hdom @thi.ng/pixel @thi.ng/hdom-canvas @thi.ng/geom @thi.ng/transducers @thi.ng/hdom-components @thi.ng/webgl @thi.ng/memoize @thi.ng/shader-ast @thi.ng/shader-ast-stdlib webgl-shadertoy | |
*/ | |
import { renderOnce } from "@thi.ng/hdom"; | |
import { PackedBuffer, canvas2d, ABGR8888, GRAY8 } from "@thi.ng/pixel"; | |
import { canvas as hdomCanvas } from "@thi.ng/hdom-canvas"; | |
import * as g from "@thi.ng/geom"; | |
import { range, map, normRange } from "@thi.ng/transducers"; | |
import { glCanvas } from "@thi.ng/webgl"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 3d version of the 2d fitIntoBounds2 | |
// https://github.com/thi-ng/umbrella/blob/feaf8d3f8c1dd3e9141a151b4e473423a6f62242/packages/geom/src/ops/fit-into-bounds.ts#L34 | |
import { Vec, MAX3, MIN3, ReadonlyVec, neg, div4, div3, abs3, sub3, dist3 } from '@thi.ng/vectors'; | |
import { concat, translation44, ReadonlyMat, scale44, mulV344 } from '@thi.ng/matrices'; | |
import { bounds, centroid } from '@thi.ng/geom-poly-utils'; | |
import { isArray, isNull } from '@thi.ng/checks'; | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
comp, | |
juxtR, | |
map, | |
mapcat, | |
partition, | |
reducer, | |
transduce, | |
wrapSides, | |
} from '@thi.ng/transducers' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Type, typedArray } from '@thi.ng/api' | |
import { MemPool } from '@thi.ng/malloc' | |
import { Vec } from '@thi.ng/vectors' | |
import { computeNewData } from './buffers' | |
const { numSliceRows, numSliceColumns, resolution } = globalState.deref() | |
const poolSize = numSliceRows * numSliceColumns * (resolution + 3) | |
const POOL = new MemPool({ size: poolSize }) | |
console.log('poolSize of', { poolSize }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from io import BytesIO | |
import numpy as np | |
import numpy.linalg as linalg | |
import scipy.interpolate as interpolate | |
from PIL import Image | |
from flask import Flask, send_file, escape, request | |
app = Flask(__name__) |
NewerOlder