Skip to content

Instantly share code, notes, and snippets.

@reinhrst
reinhrst / Dockerfile
Created November 4, 2023 04:05
emscripten for arm64 / aarch64 Docker container
FROM debian
RUN apt-get update && apt-get install -y git xz-utils python3 curl && rm -rf /var/lib/apt/lists/*
RUN git clone https://github.com/emscripten-core/emsdk.git && cd /emsdk && ./emsdk install latest-arm64-linux && ./emsdk activate latest-arm64-linux
ENTRYPOINT ["/emsdk/docker/entrypoint.sh"]
@reinhrst
reinhrst / Cargo.toml
Created June 15, 2023 10:49
Nom streaming test (blog post to follow soon)
[package]
name = "nomtest"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
nom = "7.1.3"
tempfile = "3.5.0"
@reinhrst
reinhrst / reveal-js.html
Created March 21, 2023 08:22
One page bowser-only solution to make a Reveal presentation in Markdown, with Mermaid diagrams (no Node, in-browser)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<title>reveal.js</title>
@reinhrst
reinhrst / limit.sb
Created March 20, 2023 08:00
Limiting sandbox
; run `sandbox-exec -f limit.sb $program`
(version 1)
(debug deny)
(deny default)
(import "/System/Library/Sandbox/Profiles/bsd.sb")
(allow network-outbound)
(deny network-outbound (remote tcp "localhost:*"))
(allow process-fork)
(allow process-exec*
(subpath "/opt/homebrew/")
@reinhrst
reinhrst / create-password.sh
Last active April 21, 2023 07:45
Correct horse battery staple: creates a password of english words. First param is number of words to use (default=3)
TEMPDIR="$(mktemp -d)"
NR_WORDS=${1:-3}
cd "$TEMPDIR"
curl 'https://raw.githubusercontent.com/first20hours/google-10000-english/master/google-10000-english.txt' | grep -E "^.{4,8}$" | sort | uniq > wordlist.txt
NR_LINES="$(wc -l wordlist.txt | grep -oe '\d\+')"
POSS="$(echo "$NR_LINES^$NR_WORDS" | bc)"
BITS="$(echo "l($POSS)/l(2)" | bc -l)"
CHARS="$(echo "l($POSS)/l(72)" | bc -l)"
printf 'We have %d lines; we willl take %d words; there are %.3e possibilities (%.1f bits of entropy, comparable to %.1f completely random chars (lower/upper/number/special))\n' "$NR_LINES" "$NR_WORDS" "$POSS" "$BITS" "$CHARS"
if [[ $NR_LINES -lt "4000" ]]; then
@reinhrst
reinhrst / tools.ts
Created February 20, 2023 08:54
Typescript object pick and omit functions
// typescript versions of https://stackoverflow.com/a/56592365/1207489
const pick = <T extends {}, K extends keyof T>(obj: T, ...keys: K[]) => (
Object.fromEntries(
keys
.filter(key => key in obj)
.map(key => [key, obj[key]])
) as Pick<T, K>
);
const inclusivePick = <T extends {}, K extends (string | number | symbol)>(
@reinhrst
reinhrst / npcolorsys.py
Last active December 9, 2022 10:14
RGB to HLS conversion and back
import numpy as np
def rgb_to_hls(rgb_array: np.ndarray) -> np.ndarray:
"""
Expects an array of shape (X, 3), each row being RGB colours.
Returns an array of same size, each row being HLS colours.
Like `colorsys` python module, all values are between 0 and 1.
NOTE: like `colorsys`, this uses HLS rather than the more usual HSL
"""
" This function will first check if no changes are staged in git.
" If so, it will save the current file, and then commit and push it.
" The whole function is mapped to <leader>sacp
" the function (when called manually) allows an argument that is the commit
" message
" Only use this for things where it makes sense to commit one file at a time
" (like a dev log). Else make proper commits.
function SaveAddCommitPushInfo(msg) abort
scale([4, 4, 1]) {
translate([20, 20, 0]) {linear_extrude (height=1) {circle(26);}};
color([0, 0, 0]) {
translate([0, 26, 0]) { linear_extrude (height=3){import("wifi.svg"); }; }
translate([2, 15, 1]) { linear_extrude (height=1){rotate(90){text("wifi", size=5); }}; }
translate([43, 12, 1]) { linear_extrude (height=1){rotate(90){text("hs3.pl", size=5); }}; }
translate([16, -2, 1]) { linear_extrude (height=1){text("QR", size=5); }; }
translate([28, 43, 1]) { linear_extrude (height=1){rotate(180)text("NFC", size=5);}; }
}
}
@reinhrst
reinhrst / website.yaml
Created January 5, 2022 13:40
CloudFormation stack for website with react-routing and api-reverse-proxy
AWSTemplateFormatVersion: 2010-09-09
Description: Creates an https website
Metadata: {}
Parameters:
HostedZoneName:
Description: The HostedZoneName of the zone that you want to host the website on. This has to be in the same account, and has to be active (i.e. used as the DNS server for this domain).
Type: String
HostedZoneId:
Description: The ID for the HostedZoneName