Skip to content

Instantly share code, notes, and snippets.

@reinhrst
reinhrst / adam.css
Created September 17, 2012 14:28
Spotify Style Sheets
/**
* Adam Theme / Dark Theme
* Standard Layout for Spotify Client
* Defines the basic styles for an app
* @copyright 2011 by Spotify
*/
/**
* Declarations for Adam Theme
*
@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"
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 / 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 / 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 / reply.json
Created October 7, 2021 08:28
Example Open Weather Map API call: api.openweathermap.org/data/2.5/weather?q=London&appid={API key}
{
"coord": {
"lon": -0.13,
"lat": 51.51
},
"weather": [
{
"id": 300,
"main": "Drizzle",
"description": "light intensity drizzle",
@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
"""