Skip to content

Instantly share code, notes, and snippets.

@technillogue
technillogue / docker-prune.py
Created August 13, 2022 00:16
prune docker images interactively
#!/usr/bin/python3.10
import subprocess
import humanfriendly
out = subprocess.run(
'docker images --format "{{.ID}}\t{{.Size}}\t{{.Tag}}\t\t\t{{.Repository}}"',
shell=True,
stdout=-1,
)
imgs = [img.split() for img in out.stdout.decode().split("\n") if img]
import unicodedata
def unicode_character_name(i: int) -> str:
"""Tries to get the unicode name for a given character ordinal.
Useful for finding various quotation marks"""
try:
return unicodedata.name(chr(i))
except ValueError:
return ""
import asyncio
import re
import json
import os
import subprocess
from collections import defaultdict
import requests
import asyncpg
@technillogue
technillogue / generic_types_example.py
Created February 8, 2022 07:19
turns out generics work in python
import asyncio
from typing import Generic, TypeVar
K = TypeVar("K")
V = TypeVar("V", str, list[str], dict[str, str], int, float) # some common simple JSON types
class SlowDict(Generic[K, V]):
def __init__(self) -> None:
self.d: dict[K, V] = {}
@technillogue
technillogue / accounting.sql
Created October 19, 2021 03:39 — forked from 001101/accounting.sql
Basic double-entry bookkeeping system, for PostgreSQL.
CREATE TABLE accounts(
id serial PRIMARY KEY,
name VARCHAR(256) NOT NULL
);
CREATE TABLE entries(
id serial PRIMARY KEY,
description VARCHAR(1024) NOT NULL,
amount NUMERIC(20, 2) NOT NULL CHECK (amount > 0.0),
-- Every entry is a credit to one account...
import math
from moviepy.editor import concatenate, ImageClip
import os
import platform
import subprocess
import random
import torch
# pip install pytorch-pretrained-biggan
from pytorch_pretrained_biggan import (BigGAN, truncated_noise_sample, convert_to_images)
import numpy as np
@technillogue
technillogue / json_searching_utils.py
Created March 12, 2021 20:05
find stuff in overly informative API responses
def walk(obj, path):
last = obj
for key in path:
if isinstance(last, list):
last = last[key]
else:
last = last.get(key, {})
def prune(obj, keys=["Name", "DisplayMessage", "Type", "Time"]):
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@technillogue
technillogue / ps1a.py
Created October 10, 2020 23:27
Space Cows
import time
from functools import reduce
from random import sample
from operator import itemgetter
from ps1_partition import get_partitions
# ================================
# Part A: Transporting Space Cows
# ================================
[19:18] [sylv(+Zi)] [2:Freenode/##edef(+Sns)] [Act: 1,6,7]
[##edef]
[0] 0:irssi* 1:bitlbee- 3:bash 4:bash 5:bash 6:bash 7:bash 8:supybot "technillogue@spock: ~" 19:18 31-Jan-20
[0] 0:irssi- 1:supybot 2:bitlbee 3:bash 4:bash 5:bash 6:bash 7:spock* "technillogue@spock: ~" 19:18 31-Jan-20