Skip to content

Instantly share code, notes, and snippets.

@webstrand
webstrand / latlon.jq
Created June 22, 2023 16:32
Sort list by distance
def PI: 3.14159265359;
def Radians(deg): deg * (PI / 180);
def Degrees(rad): rad * (180 / PI);
def a: 6378.137; #equitorial radius in km
def b: 6356.752; #polar radius in km
def radius_of_earth(lat1):
(((pow(((a*a)*(lat1 | cos));2))+(pow(((b*b)*(lat1 | sin));2)))/(pow((a*(lat1 | cos));2)+pow((b*(lat1 | sin));2))) | sqrt;
def Distance1(lat1;long1;lat2;long2):
@webstrand
webstrand / object-paths.ts
Created April 20, 2023 17:59
Recursively generate a list of all paths into some object
type StringSerialized<T extends object, Prefix extends string = ""> = T extends Array<any> ? {
[P in keyof T & `${bigint}`]: `-${P}` extends `${bigint}`
? | `${Prefix}${P}`
| StringSerialized<T[P] & object, `${Prefix}${P}.`>
: never
}[keyof T & `${bigint}`] : {
[P in keyof T & string]:
| `${Prefix}${P}`
| StringSerialized<T[P] & object, `${Prefix}${P}.`>
}[keyof T & string];
@webstrand
webstrand / to-excel-number.ts
Created April 19, 2023 01:48
Type-level integer to base-26 converter, excel column number style A = 0, AA = 26, AB = 27, etc
type Tuple<L extends number, T extends any[] = []> =
T["length"] extends L ? T : Tuple<L, [...T, void]>;
type Keys = [
"Z", "Y", "X", "W", "V", "U", "T", "S", "R",
"Q", "P", "O", "N", "M", "L", "K", "J", "I",
"H", "G", "F", "E", "D", "C", "B", "A"
];
type Evil = {
@webstrand
webstrand / package.json
Created April 19, 2023 00:41
Patch to increase typescript instantiation limit
{
"pnpm": {
"patchedDependencies": {
"typescript@5.0.4": "patches/typescript@5.0.4.patch"
}
}
}
@webstrand
webstrand / html-entities.re
Last active April 15, 2023 23:53
Match HTML entities including idiosyncratic entities missing a trailing semicolon
&(?:
\w+;|
(?:AE|ae|sz)lig|
[Aa]ring|
[AaEeIiOoUu](?:grave|circ)|
[AaEeIiOoUuy]?(?:acute|uml)|Yacute|
[AaNnOo]tilde|
[AEeIiOoUu]irc|
[Cc]?cedil|
[lr]aquo|
const inputText = `
yain.tain=1
yain.tether=2
foo=1
foo.bar=2
foo=2
foo.baz=3
bla.bla.bla=jlskdfjlskd.sdlfksldkfj=sldkjlskdf
`
#!/bin/bash
set -euo pipefail
# Usage like `/sbin/kexec`. Assumes the root partition is labelled `cr_root` which is
# the default on opensuse. Initrd _must_ be uncompressed, this has no logic for
# decompressing initrd before concatenation.
# Recommended dracut options for building compatible initrd:
# enhanced_cpio="yes"
# do_strip="no"
# tmpdir="/var/tmp"
const tsconfig = {
include: ["lib/**/*.ts", "lib/packages/**/*.ts", "lib/index.ts"],
exclude: ["src"],
files: ["lib/index.ts"],
typeAcquisition: {
enable: true,
disableFilenameBasedTypeAcquisition: true,
},
compilerOptions: {
allowUnreachableCode: true,
@webstrand
webstrand / regex.pl
Created March 1, 2023 16:10
regex that matches only leap years (four digits only), only for modern dates
/^
\d\d[2468][048]|\d\d[02468][48]|\d\d[13579][26]| # match (y%4 == 0 && y%100 != 0)
[02468][048]00|[13579][26]00 # match (y%100 == 0 && y%400 == 0)
$/x
#define _GNU_SOURCE
#include <stdio.h>
#include <sched.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>