Skip to content

Instantly share code, notes, and snippets.

@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
Created January 24, 2024 10:12
waitForElement function
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") {},
@mindplay-dk
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
mindplay-dk / ts-sql-libs.md
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.

Fluent

from(books).where(books.author.lower().like('%bob') and similar.

@mindplay-dk
mindplay-dk / psr-middleware.php
Created December 13, 2022 11:32
PSR Handlers as middleware
<?php
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
mindplay-dk / php-chatgpt.md
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
mindplay-dk / response.md
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

@mindplay-dk
mindplay-dk / php-upgrades.md
Last active December 28, 2023 16:46
PHP upgrades

Upgrading PHP

Guidelines for upgrading the minimum PHP version requirements of packages and projects.

This isn't meant to be an exhaustive guide to upgrading, but as a checklist for the most important upgrades.

PHP 5.3

The first version to support namespaces - any relevant PHP packages/projects usually have this version as the minimum requirement, so this document won't concern itself with upgrades prior to that.

@mindplay-dk
mindplay-dk / README.md
Created September 7, 2020 13:32
Monkey-patching/polyfill detector

This script tries to detect monkey-patching, polyfills and other hacks/overrides in the browser.

Paste it into the Chrome (or Edge) console and press ENTER.

Note that this may give false positives for window.location, window.fetch and window.length - this appears to be because these properties aren't correctly reflected by the native browser implementations, but if you know how to fix that, please post a comment.