Skip to content

Instantly share code, notes, and snippets.

View wchargin's full-sized avatar

Willow Chargin wchargin

View GitHub Profile
@wchargin
wchargin / Dockerfile
Last active February 25, 2025 16:12
protobuf.dart#952 reproducer #2
FROM dart:3.7.0-sdk
RUN apt-get update
RUN apt-get install -y protobuf-compiler libprotobuf-dev
RUN dart pub global activate protoc_plugin
@wchargin
wchargin / Dockerfile
Last active February 25, 2025 16:11
protobuf.dart#952 reproducer #1
FROM dart:3.7.0-sdk
RUN apt-get update
RUN apt-get install -y protobuf-compiler libprotobuf-dev
RUN dart pub global activate protoc_plugin
<!doctype html>
<style>
#form {
display: flex;
gap: 10px;
}
p {
margin: 0.5em 0;
}
<!doctype html>
<div id="root"></div>
<script type="module">
import React, { useEffect, useState } from "https://esm.sh/[email protected]";
import ReactDOM from "https://esm.sh/[email protected]";
import { animated, useSpring } from "https://esm.sh/@react-spring/[email protected]";
import { usePrevious } from "https://esm.sh/@uidotdev/[email protected]";
import * as turf from "@turf/turf"; // v7.0.0
const coords = (pointFeature) => pointFeature.geometry.coordinates;
const pointToLineDistanceOptions = { method: "geodesic" };
// ^ setting "planar" doesn't change things substantively
let maxError = -Infinity;
let argmaxError;
let nErrorOverOnePercent = 0;
{
"target": {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
11.991689565382663,
34.00578044047174
]
# Create GeoJSON `Feature` values
def feature: {type: "Feature", properties: {}, geometry: .};
# Create GeoJSON `Geometry` values
def geometry($type): {$type, geometry: .};
def point: geometry("Point");
def multipoint: geometry("MultiPoint");
def linestring: geometry("LineString");
def multilinestring: geometry("MultiLineString");
def polygon: geometry("Polygon");
@wchargin
wchargin / index.html
Created July 27, 2024 17:35
useStable with quick-exit
<!doctype html>
<div id="root" />
<script type="module">
import React, {
createElement as h,
useState,
} from "https://esm.sh/react@18?dev";
import { createRoot } from "https://esm.sh/react-dom@18/client?dev";
const lazyEq = (a, b) => JSON.stringify(a) === JSON.stringify(b);
@wchargin
wchargin / pan.js
Created July 2, 2024 22:38
bookmarklets for audio manipulation (speed and panning)
javascript:((pan) => { if (!window.__wcharginPanState) { const ctx = new AudioContext(); const panner = new StereoPannerNode(ctx); panner.connect(ctx.destination); const vsrcSymbol = Symbol("mediaSourceOutput"); window.__wcharginPanState = { ctx, panner, vsrcSymbol };}; const {ctx, panner, vsrcSymbol} = window.__wcharginPanState; for (const video of document.querySelectorAll("video")) { if (!video[vsrcSymbol]) { video[vsrcSymbol] = ctx.createMediaElementSource(video); video[vsrcSymbol].connect(panner); } } panner.pan.value = pan; })(Number(prompt("pan? (-1 to 1)")));
@wchargin
wchargin / cmp.js
Created February 5, 2024 23:07
sortAsciinumeric, extractNumbers: numeric-aware string sorting
/**
* A comparator that follows elements' natural ordering. Useful for comparing
* numbers: `[8, 9, 10].sort()` is broken, but `[8, 9, 10].sort(natural)` works
* as expected. Also useful as a "neutral" comparator to give to combinators.
*/
function natural(a, b) {
if (a > b) return 1;
if (a < b) return -1;
return 0;
}