Skip to content

Instantly share code, notes, and snippets.

View doctaphred's full-sized avatar
🚮
computers are bad don't use them

Frederick Wagner doctaphred

🚮
computers are bad don't use them
View GitHub Profile
@doctaphred
doctaphred / intensify.sh
Created July 27, 2021 18:42 — forked from alisdair/intensify.sh
intensifies Slack emoji creator
#!/bin/bash
# Generate a `:something-intensifies:` Slack emoji, given a reasonable image
# input. I recommend grabbing an emoji from https://emojipedia.org/
set -euo pipefail
# Number of frames of shaking
count=10
# Max pixels to move while shaking
@doctaphred
doctaphred / x509_fingerprint.py
Last active July 9, 2021 14:59
Read an X.509 cert from stdin and print its formatted SHA1 fingerprint to stdout
#!/usr/bin/env python3
import sys
from base64 import b64decode
from hashlib import sha1
cert = sys.stdin.read()
lines = cert.splitlines()
assert lines[0] == '-----BEGIN CERTIFICATE-----'
assert lines[-1] == '-----END CERTIFICATE-----'
data_lines = lines[1:-1]
@doctaphred
doctaphred / table_sizes.sql
Created April 3, 2021 17:02
Postgres table sizes
SELECT table_schema,
TABLE_NAME,
pg_size_pretty(SIZE) AS SIZE,
pg_size_pretty(total_size) AS total_size
FROM
(SELECT table_schema,
TABLE_NAME,
pg_relation_size(quote_ident(table_schema) || '.' || quote_ident(TABLE_NAME)) AS SIZE,
pg_total_relation_size(quote_ident(table_schema) || '.' || quote_ident(TABLE_NAME)) AS total_size
FROM information_schema.tables
@doctaphred
doctaphred / bulk-upsert-from-csv.sql
Created February 10, 2021 16:25
Bulk upsert from CSV in PostgreSQL
-- See https://www.postgresql.org/docs/current/sql-copy.html
-- and https://www.postgresql.org/docs/current/sql-insert.html
CREATE TEMP TABLE temp_table
(LIKE table INCLUDING DEFAULTS)
ON COMMIT DROP;
COPY temp_table (col1, col2, ...) FROM STDIN WITH CSV;
-- Assumes no header row: add `HEADER` if it has one.
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDXAW+z0e/p/EprRzUK5hzVRBgoMQUetUzYQVsmov+rpUDQdTGJVWMy86vCarbpO5s5rSHEnB/qXA9MDu+8nyciG2pIW6oJ2U2ZKC/ORetGEbXYfVJZnd82G9HDzIFztMTKXmqBP0kvlY4NIx1OlHx00WZfDhJ+9IQyvPppFu/NKEQRlT1gPusVf6thgPS7GYNi7JlJLwhS4KrYICYBr8Sq1V5ihw647E7Vm4RqZWKA0DF7u0aJlv/bideD5FAeJch8hJaxFQYjvqJsmr56vw+a/VUDTPk9/0QfyyTwvGP9D7+xKnBWnP5i6QFu+BsmOpAvarTUbETbmnGkyL0CNLM7 frederick@orthanc 2015-11-01
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC+WsRX9UQZDTOU1ZYRXNdl/ZCGhW7rUDErmWxHBhcpIQj7bcf/VUN6r/RPwWzYF3GfJ8ql7c6fDNdBWavI10TYULQBajJkLVhBCyfzq9IixG3FImFLKVc7ZfovSTcUCWaA1uw+WZeQ9vy9bSK5s2HDbOcV+l34u1L43OGpOjYRosipDuXteeN14OKUydzHw3W/ei9Rt4rzo8oZqDHwYTTRZuylxVjKt3oh5u1A/ZNHmhh7Xc+y4NCQaEmeQIYocTZFbGBirzGrn9l0+/sc5lTX7m7/uoMwDIEJjF3gvbWURKlbA+P6+37mn0CwGUmm1fe3xe9zT812Ed3QfW5O9PaAdaf2PwLEBEmXLxLeLDPOk2hebdYOXX3ucsanWpIvioowpRxV4264JVKHleGYlTMXNu0NSTs6sMib2ybIogt81+eLKq9Iquih6TWayjhD+QNRv0B/r6Es/tyVz+aQvRwOzQLGxMkP7GpFrJ497DtHP8tgaBixWAGPHw8ICOav7s0CfCVfcCh1X5ub+Q5B7+W0tEB6JLJVttYvWiqXqQIwu6EoEIXuG65PUjblhtHunT
@doctaphred
doctaphred / turbocache.py
Created October 23, 2020 19:44
"Yo dawg, I heard you like caching..."
from functools import lru_cache
from types import FunctionType
def cache(func):
return lru_cache(maxsize=None)(func)
class Vector(tuple):
# [small brain]
@doctaphred
doctaphred / cap.py
Created February 5, 2020 03:30
Content Addressable Python! (work in progress)
import dill
x = 1
def print_globals(max_value_len=79):
"""
>>> print_globals(40) # doctest: +ELLIPSIS
globals: {
@doctaphred
doctaphred / print-slack-clipboard
Last active April 8, 2022 23:38
Workaround for copy/pasting Slack's broken multiline code blocks
#!/usr/bin/env python3
"""
Slack's new WYSIWYG format broke copy/pasting multiline code blocks:
blank lines are omitted when pasting as plain text.
If you can get the HTML contents of the clipboard, this script can
output the expected text, blank lines and all.
The macOS clipboard is complicated, and the built-in `pbpaste` command
won't let you get the contents as HTML. (The `-Prefer` option seems to
@doctaphred
doctaphred / python2-wyd
Last active September 19, 2019 22:13
Some surprising comparison behaviors in Python 2
Some surprising comparison behaviors in Python 2.
You can confirm these behaviors via doctest:
python2 -m doctest python2-wyd
Careful, though: some of the results change if the filename is more than
13 characters long.
"""Example usage:
In [1]: !cat ayy.s
.text
.global _start
.type _start, @function
_start:
movq $10, %rdx
pushw $10