Skip to content

Instantly share code, notes, and snippets.

@tomtheisen
tomtheisen / README.md
Last active December 7, 2023 16:56
My Beef With React

What's wrong with React anyway?

Here's a partial list of my problems with React. Some may be matters of opinion. There may be more.

Component identity

Reconciliation matches freshly rendered components with stored state. It usually does what you wanted. Setting keys affects the algorithm somehow. I'd prefer explicit component identity to a mostly-correct heuristic.

Stale references from useState

@tomtheisen
tomtheisen / day01.md
Last active July 21, 2023 04:47
React Journey

My Journey to the Center of the React

At the end of this, I'll know I failed if I can't write my own useState.

Tutorial

Here we go. The very first tutorial. Should be simple. https://react.dev/learn/tutorial-tic-tac-toe

It has some kind of online sandbox thing. I prefer local dev for this, as I think their sandbox is going to be hiding smoke and mirrors. I want to be able to run react on arbitrary places outside their walled gardens. Fortunately, they have instructions for doing it.

@tomtheisen
tomtheisen / 01-1.utm
Last active December 13, 2022 17:39
AOC 2022 Mungers
#(
@/(\d+)\n(\d+)/=>{$1 $2 +}
fx /\d+/ => { _ get(max) max set(max) }
{ get(max) }
)
@tomtheisen
tomtheisen / theory.md
Created August 17, 2022 14:08
Harmonic Music Theory Crash

This road leads directly to functional-harmony-random-progression-generator.

There's a lot more stuff in music theory.

Notes

█ █ █ │ █ █ │ █ █ █ │ █ █ │ █ █ █ 
█ █ █ │ █ █ │ █ █ █ │ █ █ │ █ █ █ 
│ │a│b│c│d│e│f│g│a│b│c│d│e│f│g│ │ 
@tomtheisen
tomtheisen / README.md
Last active December 18, 2021 06:01
Advent of Munging 2021
@tomtheisen
tomtheisen / universal-reducer.ts
Created July 1, 2020 05:57
The Last Reducer You'll Ever Need
interface UniversalAction<TState> {
type: "UNIVERSAL";
map: (previous: TState) => TState;
}
function universalAction<TState>(map: (previous: TState) => TState): UniversalAction<TState> {
return { type: "UNIVERSAL", map };
}
// all other reducers are now redundant
@tomtheisen
tomtheisen / aoc2019stax.md
Last active December 15, 2019 05:49
AOC2019 stax solutions

AOC2019 stax solutions

Here are some of my stax solutions for Advent of Code 2019. Input goes verbatim in the input box.

Day 1

Part 1

@tomtheisen
tomtheisen / gist:0b059caf2889fe54dacfb08ba5d3cf2a
Created August 30, 2019 15:57
Precise ToString() for double
using static System.Double;
using static System.Math;
using static System.Numerics.BigInteger;
using System.Numerics;
public static class DoubleConvert {
public static string Precisely(this double a) {
if (IsInfinity(a) || IsNaN(a)) return a.ToString();
if (a == 0) return 1 / a < 0 ? "-0.0" : "0.0";
BigInteger n = 0, d = 1, p = 1;
declare var $: any;
function select2EventDispatch(el: HTMLElement, events: string[]) {
let dispatching = false;
$.fn.select2 && $.fn.select2.amd.require(
["select2/utils"], function (Utils: any) {
const instance = Utils.GetData(el, "select2");
instance && events.forEach(ev => {
instance.on(ev, () => {
if (dispatching) return; else dispatching = true;
@tomtheisen
tomtheisen / kolmogorov.stax
Last active August 11, 2019 04:55
This program will produce a stax program that outputs its input.
Ld_X store input in X
c"Initial size: `%"P
{
xx2B
xVp:SY{{Vpxaz:r-f}M keep only substrings that leave an unused ascii char after their removal
|=h#~
%RD{d find the length of the longest substring that occurs the most times
xx_B
y{{Vpxaz:r-f}M keep only substrings that leave an unused ascii char after their removal
|=h#