Skip to content

Instantly share code, notes, and snippets.

View ricokahler's full-sized avatar
💭
recovering from burnout

Rico Kahler ricokahler

💭
recovering from burnout
View GitHub Profile
@ricokahler
ricokahler / README.md
Created June 11, 2021 21:50
another proof of turning completeness — 4 years later

there's a somewhat older github issue in the typescript repo that made the observation that typescript was turning complete

linked was also a proof via implement a turing machine within the typesystem.

that proof no longer works, and with the addition of template literal types, there comes a much more straightforward way to do this. that's what this is — a proof that typescript's type system is turning complete, 4 years later

see [here](https://www.typescriptlang.org/play?#code/PTAEGUBUCUEkDkDioCyBBesAKBVAMmpLAPLyiTHF7gBQALgJ4AOApqAGICWATgM50AeSKBYAPOiwB2AE16h+3TpIDmAPlABeciPFTZoAAYASAN5KAZi26gcAX1MKly2wdAB+G6ABcoAOS-6ZjZoFgBbAHsANxYuPkFhMQkZOUcVdS0E3WTDBzpFFXszSUtrO1cPHG8-AMDWUBDovhYBSsS9FLyndM827P8aUHdqgarWrP1fAEZfUAAfPwAGAMGKkZ9jEwarXmaQiOjY-hbVVULDwRxTgxpatjwAQyPMpP1UtU0OHiOtpqET2-qYSiLAeTx0Lw6+XeWh+OwEe2

@ricokahler
ricokahler / register.js
Created September 4, 2020 00:48
register function
const path = require('path');
require('@babel/register')({ extensions: ['.js', '.ts', '.tsx'] });
const args = process.argv.slice(2);
if (args[0] === '--') {
const filename = args[1];
// require relative to the root
require(path.resolve(__dirname, '../', filename));
}
@ricokahler
ricokahler / index.js
Last active May 23, 2020 22:57
color2k in one file
import parseToRgba from '@color2k/parse-to-rgba';
export { default as parseToRgba } from '@color2k/parse-to-rgba';
// taken from:
/**
* Parses a color in hue, saturation, lightness, and the alpha channel.
*
* Hue is a number between 0 and 360, saturation, lightness, and alpha are
* decimal percentages between 0 and 1
*/
@ricokahler
ricokahler / memoIgnoringFunctions.js
Last active September 19, 2019 05:12
React.memo but it ignores functions changes
import React, { memo, useMemo, useLayoutEffect, useRef } from 'react';
import objectHash from 'object-hash';
import _partition from 'lodash/partition';
import _fromPairs from 'lodash/fromPairs';
/**
* an HOC that uses `React.memo` to memoize component expect it ignores changes
* to functions while also keeping those functions up-to-date somehow
*/
function memoIgnoringFunctions(Component, propsAreEqual) {
@ricokahler
ricokahler / Component.js
Created September 19, 2019 03:08
Only add the event listener once
import React, { useCallback } from 'react';
function usePullValue(value) {
const ref = useRef(value);
useLayoutEffect(() => {
ref.current = value;
}, [value]);
return useCallback(() => {
@ricokahler
ricokahler / api.ts
Last active July 3, 2018 14:05
Retain Data API
interface Request {
queries: Array<Query>;
filters?: Filter;
}
interface Response extends Array<Result> {}
interface Result {
id: string;
results: Array<number>;
@ricokahler
ricokahler / .gitignore
Last active June 7, 2018 13:02
Material-ui typescript bug
node_modules
@ricokahler
ricokahler / map-promises.ts
Created February 7, 2018 17:02
map promises
export async function sequentially<T, R>(list: T[], asyncFunction: (t: T) => Promise<R>) {
const newList = [] as R[];
for (const i of list) {
newList.push(await asyncFunction(i));
}
return newList;
}
/*
// then use like so:
@ricokahler
ricokahler / map-reduce.ts
Created April 7, 2018 15:10
map - reduce in javascript
class Something {
foo: string;
bar: string;
x: number;
constructor(x: number) {
this.x = x;
this.foo = 'foo';
this.bar = 'bar';
}
}
@ricokahler
ricokahler / index.html
Last active March 9, 2018 21:08
simple web app
<html>
<head>
<title>what up</title>
</head>
<body>
<h1 class="foo"></h1>
<div class="stuff"></div>
<script>
async function loadData() {
const response = await fetch('https://api.github.com/users/ricokahler/gists');