Skip to content

Instantly share code, notes, and snippets.

View jawj's full-sized avatar

George MacKerron jawj

View GitHub Profile
@jawj
jawj / sslrootcert.md
Last active March 24, 2025 17:29
sslrootcert=system support
@jawj
jawj / gist:04a90e51196ac054d6741c8d079d9cff
Created January 16, 2025 18:29
Signature algorithm digest name from X.509 certificate
function x509Error() {
throw new Error('Could not extract signature algorithm digest from server certificate to perform channel binding')
}
function readASN1Length(data, index) {
let length = data[index++]
if (length < 0x80) return { length, index }
const lengthBytes = length & 0x7f
if (lengthBytes > 4) x509Error()
@jawj
jawj / pgconf.eu.2023.sql
Created November 12, 2024 17:19
Load pgconf PDFs in psql
\set contents `base64 < "path/to/pgconf.eu.2023/2023.pgconf.eu Zero Downtime PostgreSQL Upgrades.pdf"`
insert into docs (name, fulltext) values ($$2023.pgconf.eu Zero Downtime PostgreSQL Upgrades.pdf$$, rag.text_from_pdf(decode(:'contents','base64')));
\set contents `base64 < "path/to/pgconf.eu.2023/20231215_PGConfEU_What-cant-pgBackRest-do-for-you.pdf"`
insert into docs (name, fulltext) values ($$20231215_PGConfEU_What-cant-pgBackRest-do-for-you.pdf$$, rag.text_from_pdf(decode(:'contents','base64')));
\set contents `base64 < "path/to/pgconf.eu.2023/A journey into postgresql logical replication.pdf"`
insert into docs (name, fulltext) values ($$A journey into postgresql logical replication.pdf$$, rag.text_from_pdf(decode(:'contents','base64')));
\set contents `base64 < "path/to/pgconf.eu.2023/Breaking Up Massive Tables with Partitioning.pdf"`
insert into docs (name, fulltext) values ($$Breaking Up Massive Tables with Partitioning.pdf$$, rag.text_from_pdf(decode(:'contents','base64')));
\set contents `base64 <
@jawj
jawj / hex.js
Last active November 12, 2024 17:09
Fast hex encoding in JS using (roughly) Duff's device
const
toHexDecoder = new TextDecoder(),
charCodes = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102], // 0123456789abcdef
u16Lookup = new Uint16Array(256),
isLittleEndian = new Uint8Array((new Uint16Array([0x0102]).buffer))[0] === 0x02;
if (isLittleEndian) for (let i = 0; i < 256; i ++) u16Lookup[i] = charCodes[i & 0xF] << 8 | charCodes[(i >>> 4) & 0xF];
else for (let i = 0; i < 256; i ++) u16Lookup[i] = charCodes[i & 0xF] | charCodes[(i >>> 4) & 0xF] << 8;
export function toHex(data) {
@jawj
jawj / whc-sites-2021.psql
Created February 1, 2023 20:49
SQL to load UNESCO World Heritage Sites 2021 into PostgreSQL/PostGIS
-- == create schema == --
begin;
drop type if exists category cascade;
create type category as enum ('Natural', 'Cultural', 'Mixed');
drop type if exists category_short cascade;
create type category_short as enum ('N', 'C', 'C/N');
@jawj
jawj / whc-sites-2021.csv
Created February 1, 2023 20:39
World Heritage Sites 2021 | Data from https://whc.unesco.org/en/syndication/ converted to CSV | Copyright © 1992 – 2022 UNESCO/World Heritage Centre
We can't make this file beautiful and searchable because it's too large.
unique_number,id_no,rev_bis,name_en,name_fr,short_description_en,short_description_fr,justification_en,justification_fr,date_inscribed,secondary_dates,danger,date_end,danger_list,longitude,latitude,area_hectares,C1,C2,C3,C4,C5,C6,N7,N8,N9,N10,criteria_txt,category,category_short,states_name_en,states_name_fr,region_en,region_fr,iso_code,udnp_code,transboundary
@jawj
jawj / install.txt
Last active March 29, 2023 05:44
Debug serverless driver in Chrome + Wireshark from any AWS region
# using AWS Lightsail, Ubuntu 20.04
# in dashboard, allow TCP on port 5901
sudo apt update && sudo apt upgrade -y && sudo apt install -y \
tigervnc-standalone-server tigervnc-xorg-extension \
xfce4 wireshark node # pick any window mgr, say yes to non-root packet capture
# set up VNC
@jawj
jawj / iso8601us.ts
Created May 23, 2021 15:40
Convert between 6dp ISO8601-format dates and Unix epoch microseconds in Zapatos
import { DateString, strict } from 'zapatos/db';
/**
* Convert a `DateString` (to 6dp) to microseconds since 1 January 1970.
* Nullability is preserved (e.g `DateString | null` becomes `number | null`)
* using `strict`. Note: only dates before 5 June 2255 can be represented
* within `Number.MAX_SAFE_INTEGER` this way.
*/
export const toUnixMicroseconds = strict((d: DateString) => {
const
@jawj
jawj / LinkableTextView.h
Last active January 10, 2020 12:34
UITextView with tappable links even when not selectable
//
// LinkableTextView.h
//
// Created by George MacKerron on 2020/01/09.
// Copyright © 2020 George MacKerron. MIT licenced.
//
@import UIKit;
@interface LinkableTextView : UITextView
@jawj
jawj / liars-cheats-thugs-racists-crooks.md
Last active November 26, 2019 11:45
Liars, cheats, thugs, racists and crooks — references

Liars

Johnson repeated the claim that leaving the EU would save £350m/week in contributions even after the ONS told him it was “a clear misuse of official statistics”. Full Fact

The Department for Work and Pensions has spent £100s of millions of public money disseminating misinformation about Universal Credit for Tory political advantage. The Guardian

Cheats

During the leaders’ TV debate, the Tory press Twitter account (@CCHQPress) rebranded as factcheckUK in order to dupe people into thinking their partisan commentary was impartial. BBC News