Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / image-url.ts
Last active September 28, 2023 15:25
Rotate image preview to compensate for EXIF orientation (Javascript / Typescript)
// Based on: https://stackoverflow.com/a/46814952/283851
/**
* Create a Base64 Image URL, with rotation applied to compensate for EXIF orientation, if needed.
*
* Optionally resize to a smaller maximum width - to improve performance for larger image thumbnails.
*/
export async function getImageUrl(file: File, maxWidth: number|undefined) {
return readOrientation(file).then(orientation => applyRotation(file, orientation || 1, maxWidth || 999999));
}
@mindplay-dk
mindplay-dk / GDistanceHelper.php
Created January 16, 2014 15:34
Helper class for Yii to build SQL queries that calculate the geographical distance from a point (in miles) - can be used with models that have latitude/longitude coordinates to filter by (and/or compute) the distance from a point.
<?php
/**
* @version 1.0
* @author Rasmus Schultz <http://blog.mindplay.dk/>
* @license LGPL3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
*/
/**
* Helper-class to build SQL queries that calculate the geographical distance
@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 / migrator.php
Created June 16, 2012 19:11
Migrate a PHP codebase to use namespaces.
<?php
/**
* Namespace Migration Script
*
* @author Rasmus Schultz <rasmus@mindplay.dk>
* @license http://www.gnu.org/licenses/gpl-3.0.txt
*
* This script will scan through an entire PHP codebase and rewrite the
* scripts, adding a namespace clause based on the directory structure,
@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 / jquery.column.js
Created July 30, 2012 20:31
jQuery: find all cells (td/th) in a column of a table
/**
* Find all cells (td/th) in the column of the current cell.
* (excluding rows with cells that span multiple columns.)
*/
(function($) {
$.fn.column = function() {
return $(this)
.filter('th, td')
@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 / restart-sidebar.vbs
Created June 17, 2011 21:22
Restart the Windows 7 Sidebar (for easier Gadget development)
Set WMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
For Each sidebar in WMI.ExecQuery("Select * from Win32_Process Where Name = 'sidebar.exe'")
sidebar.Terminate()
Next
sidebarPath = "C:\Program Files\Windows Sidebar\sidebar.exe"
CreateObject("Wscript.Shell").Run """" & sidebarPath & """", 0, False