Skip to content

Instantly share code, notes, and snippets.

@mindplay-dk
mindplay-dk / translation.ts
Created February 28, 2025 08:07
Type-safe language translations in TypeScript
// We define a default master language and primary translation
// Types are extracted from that, and other translations must
// then conform to the primary translation.
const DANISH = {
"Hello {name}!": "Hej {name}",
"Welcome to the world": "Velkommen til Verden",
}
type TranslationKey = keyof typeof DANISH
@mindplay-dk
mindplay-dk / convert.js
Created December 17, 2024 12:07
a horrible script to convert the entire PHP manual from HTML files to Markdown
const fs = require('fs');
const path = require('path');
const TurndownService = require('turndown');
// Directories
const inputDir = path.join(__dirname, 'html');
const outputDir = path.join(__dirname, 'markdown');
// Initialize Turndown
const turndownService = new TurndownService({
@mindplay-dk
mindplay-dk / bnf.md
Created August 16, 2024 09:33
Making sense of BNF, ABNF, EBNF syntax differences and history

Claude.ai just helped me make a whole lot more sense of the absolute mess that is BNF-family syntaxes. 🤔

I just discovered ABNF is actually a standard, RFC 4234.

Why isn't this more widely used?

BNF in the wild drives me nuts - no two grammars are ever written in the same flavor of BNF, and often grammars are published as merely "BFN" neglecting to even specify which BNF variant was used.

Are there any other BNF variants that are properly standardized?

@mindplay-dk
mindplay-dk / bias-quiz.md
Last active July 18, 2024 14:54
Bias quiz with Claude (or ChatGPT)

I want you to quiz me in my knowledge of biases, using the following method:

  1. Provide a brief and relatable (first- or third-person) story describing a hypothetical situation, in which one of these biases occur - and ask me to identify the type of bias.
  2. If I guess wrong the first time, provide a clue - something relating to the story. But don't be too obvious.
  3. If I guess wrong a second time, provide the answer, and relate it to the story - include a brief explanation of how/why my answer was wrong, explain the name of the correct bias, and the difference between the correct bias versus my answer.
  4. Begin from step 1 again with a different bias.

Below is a list of biases I'd like you to quiz me on:

  • Ambiguity Effect Bias: The tendency to choose options with known outcomes over those with unknown outcomes.
@mindplay-dk
mindplay-dk / vivaldi.css
Last active July 17, 2024 09:02
Vivaldi custom CSS
div#tabs-tabbar-container {
padding-top: 5px !important;
height: 34px !important;
}
div#header {
min-height: calc(40px / var(--uiZoomLevel)) !important;
}
.button-toolbar.workspace-popup.tabbar-workspace-button.button-menu {
@mindplay-dk
mindplay-dk / css-capture.js
Last active March 25, 2024 12:38
Capture CSS rules being used on the page
/**
* This script captures all CSS rules that are in use on the current page.
*
* - Paste the script into the browser console.
* - Run `collector.rules` to get a list of CSS rules in use.
* - As a diagnostic, run `collector.rulesWithComments` to get a list of CSS rules with comments.
*/
var collector = (() => {
const rulesInUse = new Set();
@mindplay-dk
mindplay-dk / factory.php
Created March 24, 2024 16:53
factory.php
<?php
class UserProvider
{
public function __construct(
#[Service("user.cache-path")]
public readonly string $cache_path
) {}
#[Service("user.cache")]
@mindplay-dk
mindplay-dk / reactive.js
Last active January 27, 2024 13:51
reactive JS 🤔 everything is a signal? 🤷‍♂️
/*
I know this is probably bonkers and there must be a million reasons this wouldn't
actually work, but hear me out... what if variables were reactive by default?? 😏
*/
function fetchTodayFortune() {
return fetch("https://api.example.com/fortune")
.then((response) => response.json())
@mindplay-dk
mindplay-dk / waitForElement.js
Last active March 25, 2024 10:17
waitForElement function (wait for element matching selector)
let animationCounter = 0;
export function waitForElement(selector) {
return new Promise((resolve) => {
const elem = document.querySelector(selector);
if (elem) {
resolve(elem); // already in the DOM
}
@mindplay-dk
mindplay-dk / ReflectionParameter.md
Created October 11, 2023 10:40
PHP ReflectionParameter overview

With so many parameter modes in PHP, I wanted to know exactly what ReflectionParameter is going to return.

<?php

class Database {}

$fns = [
    function ($str) {},
    function ($str ="hello") {},