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
{
"@type": "html",
"value": "<p>Example</p>"
}

My least favorite part of the web platform

Behold, the worst part of the web platform: user gestures.

In short, let's say you've built a web application that edits maps, or… does something else, hypothetically. You implement file saving in that application using the fancy new native browser APIs. Then you have to do some stuff to process or load the file when you click Save - like if you're converting the file and you want to do it in a WebWorker for optimum smoothness. Soon, you will meet this error message:

SecurityError Failed to execute 'showSaveFilePicker' on 'Window': Must be handling a user gesture to show a file picker.

This is just one example of "user gesture" restrictions: you can also find them when you request permissions or attempt to open windows. Basically, to crack down on bad actors or misuse, the browser restricts certain functions to only being called in connection with a click handler.

@tmcw
tmcw / stripe.md
Created December 21, 2021 14:03
Stripe webhooks in development

Micro-devlog for something tiny.

Placemark uses Stripe, and uses their webhooks. You can use Stripe without webhooks, but it's better to build with the webhooks.

I'm developing the account system actively, so I want the webhooks to work in local development. Thankfully, the stripe cli supports proxying webhooks from your development Stripe environment to your local setup. You run

$ stripe listen --forward-to localhost:5000/stripe_webhooks

The Utility Token Puzzle

I've written about IPFS twice: in 2017 and 2019. If I were sticking to a biyearly schedule, this would be my time to try it again. After all, one of the key pieces of Protocol Labs infrastructure, Filecoin, launched late last year. The tokens that run Filecoin are now worth billions of dollars.

I looked at the state of Filecoin from the perspective of using it, and I'm sure there's a funny post to be written about someone actually trying to do that - use it - maybe with a five-hour YouTube walkthrough. But I have a deeper question.

How is any of this supposed to work?

I imagine that Filecoin, and other "utility token" systems, work like this:

const got = require("got");
const selectAll = require("hast-util-select").selectAll;
const unified = require("unified");
const parse = require("rehype-parse");
(async function () {
const { body } = await got("https://macwright.com/");
const ast = await unified()
.use(parse, { emitParseErrors: true, duplicateAttribute: false })
const [map, geojson] = await Promise.all([
new Promise((resolve) => map.on("load", () => resolve(map))),
fetch("foo.json").then((r) => r.json()),
]);

Here's a sort of unsolved logic/programming problem.

I made this site, Old Fashioned, for cocktail recipes. It has structured data for ingredients and recipes for cocktails. And one of its neat features is that, given certain ingredients, it shows you what's possible or what's nearly possible.

I've been thinking about the opposite angle: from which set of 5 ingredients can you make the highest number of different cocktails? How does one correctly solve this problem.

If formal descriptions are your jam: let's say:

  • You have 100 different ingredients
  • You have 20 cocktails, each of which use 2-6 ingredients
@tmcw
tmcw / README.md
Last active December 8, 2020 18:53
Icons on the internet

Is there a fully great way to do icons on the internet?


What these are:

  • SVG as IMG: You have an SVG file. Create an img element. SVG is the src of that image element. It's an img tag.
  • Inline SVG: You put an `
const glob = require("glob");
const fs = require("fs");
const path = require("path");
const { PurgeCSS } = require("purgecss");
const cssnano = require("cssnano");
const cheerio = require("cheerio");
const minify = require("html-minifier").minify;
const sharp = require("sharp");
// This runs on Netlify after Jekyll builds a full site.

Hi Tom!

Here's what the Markdown for a book looks like on macwright.org:

---
categories:
  - book
layout: book
title: 'My Year of Rest and Relaxation'