Skip to content

Instantly share code, notes, and snippets.

View tmcw's full-sized avatar
💭
merging your prs

Tom MacWright tmcw

💭
merging your prs
View GitHub Profile
@tmcw
tmcw / README.md
Created September 10, 2026 13:56
String multi search benchmark

Takeaways:

  • indexOf & includes are a lot faster than regexes for this test set
  • aho-corasick implementation ( https://github.com/BrunoRB/ahocorasick ) could be optimized, but the baseline performance is very slow, relative to primitives
 ✓ shared/secretScanning/scan.bench.ts 18972ms
     name                      hz     min     max    mean     p75     p99    p995    p999     rme   samples
   · regex match     6,506,410.47  0.0000  0.9696  0.0002  0.0002  0.0002  0.0002  0.0004  ±0.36%   6506411
 · regex test 7,752,708.05 0.0000 0.0453 0.0001 0.0001 0.0002 0.0002 0.0002 ±0.03% 7752709
┌───────────────────────────────────────────┬────────────────────────┐
│ Package │ License │
├───────────────────────────────────────────┼────────────────────────┤
│ @placemarkio/turf-jsts │ (EDL-1.0 OR EPL-1.0) │
├───────────────────────────────────────────┼────────────────────────┤
│ sha.js │ (MIT AND BSD-3-Clause) │
├───────────────────────────────────────────┼────────────────────────┤
│ pako │ (MIT AND Zlib) │
├───────────────────────────────────────────┼────────────────────────┤
│ @maplibre/mlt │ (MIT OR Apache-2.0) │

Mapbox made their map renderer, Mapbox GL, closed-source in 2020. I left in 2017 so wasn't involved in this decision, but I worked on Mapbox GL and know the rest of the narrative. Mapbox was part of a wave of open-core startups that released the core of their products as open source and were able to make a decent business as well as do a good thing for the world. The amount of time and money that Mapbox put into open source code is pretty unrivaled. But, big competitors started just running the same versions of the same software for cheaper and the vibes shifted and so decisions like this one was made.

MapLibre started as a fork of Mapbox GL 1.x, the open source version, and has evolved a lot since then but still owes a lot to the original. The maintainers are very cool about this and the repo makes the lineage clear. But there's a narrative of rebelling against the corporation by using a version of the code open sourced by the corporation. That narrative hurts because I saw both the effort put into the i

import express from "express";
const app = express();
app.use(express.json());
function factorial(n) {
if (n === 1) return 1;
return n * factorial(n - 1);
}
export default async (req) => {
const headers = {
'Content-Type': 'text/css',
'Netlify-Vary': 'cookie=scheme',
'Vary': 'Cookie',
// max-age in seconds = cache for 1 hour
'Netlify-CDN-Cache-Control': 'public, max-age=3600, stale-while-revalidate=120',
'Cache-Control': 'public, max-age=360'
};
if (req.method === 'GET') {
@tmcw
tmcw / README.md
Last active September 18, 2026 01:20

Tampermonkey userscripts for automatically adding credit card offers

import {
encodeBase64,
decodeBase64,
} from "https://deno.land/std/encoding/base64.ts";
import process from "node:process";
import SuperJSON from "npm:superjson@2.1.0";
SuperJSON.registerCustom(
{
isApplicable: (v: any): v is Function => typeof v === "function",
import { getCollection } from "astro:content";
import type { APIRoute } from "astro";
export async function getStaticPaths() {
const docs = await getCollection("docs");
return docs.map((doc) => ({
params: { slug: doc.slug },
props: doc,
}));
}
import { Draft2019 } from "json-schema-library";
console.log(Draft2019);
@tmcw
tmcw / README.md
Last active May 28, 2024 13:49
CodeMirror extension to detect and fix missing JSX Pragma

We make JSX configuration a per-val setting by requiring a jsxPragma: https://docs.deno.com/runtime/manual/advanced/jsx_dom/jsx

But most code doesn't do that and relies on a project-wide jsx setting. So, to provide better DX for missing JSX pragmas, we use this CodeMirror extension that detects the lack of a pragma and the presence of JSX syntax, by using CodeMirror's existing syntax tree.