Skip to content

Instantly share code, notes, and snippets.

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 / factory.php
Created March 24, 2024 16:53
class UserProvider
public function __construct(
public readonly string $cache_path
) {}
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("")
.then((response) => response.json())
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 /
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.


class Database {}

$fns = [
    function ($str) {},
    function ($str ="hello") {},
mindplay-dk / twitter.svg
Created September 7, 2023 07:36
Twitter Logo
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
mindplay-dk /
Last active October 14, 2023 16:14
TypeScript SQL libs

Type-safe TS SQL Libs

A list of query-builders and other SQL query and/or schema abstractions.

Libraries with no activity for 2+ years will be considered "dead", as these are not keeping up with the language or ecosystem - but they may be added and may remain on the list, if they contain different or interesting ideas.


from(books).where('%bob') and similar.

mindplay-dk / psr-middleware.php
Created December 13, 2022 11:32
PSR Handlers as middleware
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
// There are essentially 3 handler/middlerware patterns:
mindplay-dk /
Created December 12, 2022 10:29
Teaching ChatGPT new PHP syntax

I was curious if we could use ChatGPT to generate a new and better manual for PHP.

This example was interesting enough that I figured it was worth posting.

It looks like ChatGPT does not know PHP 8.1 - the latest version it seems to know is PHP 8.

When asked to explain the first class Callable(...) syntax (introduced in PHP 8.1) it does explain how to generate something that is functionally similar, using e.g. fn($car) => $car->drive() rather than $car->drive(...). So it understands the concept, it just doesn't know about the new syntax.

But here's the wild part: I then proceded to explain the new syntax to it, and asked it to explain again using the new syntax - and it did it. 😮

mindplay-dk /
Last active July 16, 2022 14:45
Named registrations in dependency injection containers

In response to this answer:

The built-in dependency injection container does not support named dependency registrations, and there are no plans to add this at the moment.

One reason for this is that with dependency injection, there is no type-safe way to specify which kind of named instance you would want. You could surely use something like parameter attributes for constructors (or attributes on properties for property injection) but that would be a different kind of complexity that likely wouldn’t be worth it; and it certainly wouldn’t be backed by the type system, which is an important part of how dependency injection works.

I'm not sure what is meant by "type-safe" here?

The way service providers are provisioned in .NET today (via service providers and descriptors) is only "type-safe" in the sense that e.g. constructors specify the required types of dependencies that should be injected - th