Skip to content

Instantly share code, notes, and snippets.

View pjlsergeant's full-sized avatar
🙇‍♂️
I don't really have time for this anymore

Peter Sergeant pjlsergeant

🙇‍♂️
I don't really have time for this anymore
  • Bangkok, Thailand
View GitHub Profile
/*
# WHAT
Do a pre-pass of tagged template literals, interpolating strings
# WHY
Consider Prisma's `$queryRaw()`; it accepts a tagged template literal, and
/*
# Why
Asynchronously instantiate a singleton only once, even if many calls are made,
eg, a handler that lazy-loads a resource, but might be called several times
before it's ready.
# Synopsis
@pjlsergeant
pjlsergeant / prisma-session.ts
Created February 19, 2024 05:31
Prisma / express-session simple integration
// Offensively simple shim on top of https://www.npmjs.com/package/connect-pg-simple
import { PrismaClient } from '@prisma/client';
import connectPgSimple from 'connect-pg-simple';
import session from 'express-session';
import { format } from '@scaleleap/pg-format';
type Debugger = (arg: Record<string, unknown>) => Promise<void>;
export const consoleDebugger: Debugger = async (payload) => {

Pecol

The Pecol (Pete's Columns) is a text-based format designed for handling structured data on the command line. It is similar to TSV, but adds some additional structure in the form of type annotations for each column.

The Pecol format is particularly well-suited for use on Linux systems, where it can be used in conjunction with various command line tools for data processing and analysis.

Format

Each Pecol file starts with a magic string on the first line, followed by a header row and one or more data rows.

#!perl
# Dictionary encrypted so the keys aren't enumerable, but where possession of
# a key allows you to decrypt the value.
#
# eg: a translations file where you don't want people to be able to know all
# the translated strings, but you do want someone with a string to be able
# to translate it
use strict;
#!perl
use strict;
use warnings;
# key insights:
#
# * things having to happen "simultaneously" is misleading. Because we only add
# into the middle each time, you can start with each pair, work out what
# happens there, and then move on to the next one
@pjlsergeant
pjlsergeant / eg.ts
Created June 21, 2021 03:18
A comprehensive 5-line introduction to generics
const wrapP = <T>( x: T ) : Promise<T> => Promise.resolve(x);
const wrapL = <T>( x: T ) : T[] => [x];
const foo = wrapP("string"); // Promise<string>
const bar = wrapL(5); // number[]
// PS: you can also add constraints
@pjlsergeant
pjlsergeant / js-refresher.md
Last active May 30, 2021 14:25
Quick JS OO Refresher

Quick JS OO Refresher

I wrote this trying to get closures and function properties straight in my head, and it was useful for that. I'm not sure if it has any value for showing how JS's OO system works, but it might.

Can you guess what this prints?

[function(){ console.log( this )}][0]();

adet - Drive docker, docker-compose, and aws ecs from one config

adet attempts to provide maximum DWIM for projects using docker, Docker Compose and AWS ECS from YAML configuration files. It supports the three projects I'm working on nicely, each one of which has several component Docker images organized into tasks and services, and deployed on ECS.

Synopsis

Login

@pjlsergeant
pjlsergeant / util-graph.xsl
Created May 8, 2017 04:35
BFS algorithm in XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<!-- Templates which operate on directed graphs -->
<xsl:import href="util-map.xsl"/>
<!--
Simple breadth-first search implementation to return a tree from a starting node
-->
<xsl:template name="generate-paths">