Skip to content

Instantly share code, notes, and snippets.

import sys
import shutil
import argparse
from PIL import Image
parser = argparse.ArgumentParser()
parser.add_argument("path")
parser.add_argument("--width", type=int, default=None)
parser.add_argument("--height", type=int, default=None)
args = parser.parse_args()
def _cluster(sorted_nums_ids: list[tuple[int, str]], max_reduction: int) -> list[tuple[int, str]]:
"cluster integers by reducing them by no more than max_reduction"
# if the entire range can be reduced to equal the lowest number without violating max_reduction
if sorted_nums_ids[-1][0] - sorted_nums_ids[0][0] <= max_reduction:
new_num = sorted_nums_ids[0][0]
return [(new_num, _id) for _, _id in sorted_nums_ids]
# divide and conquer. split the range at the biggest gap
# for each element, the corresponding gap is the distance between it and the previous element
gaps = [-1]
for i, (num, _) in enumerate(sorted_nums_ids[1:], start=1):
todos_fixmes:
image: alpine
script:
- apk add ripgrep curl
- todo_count="$(rg TODO . | wc -l)"
- fixme_count="$(rg FIXME . | wc -l)"
- curl "https://shields.io/badge/TODOs-$todo_count-blue" > todos.svg
- curl "https://shields.io/badge/FIXMEs-$fixme_count-red" > fixmes.svg
artifacts:
paths:
ICAgICAgICAgIBtbMzg7NTs5N23iloHiloLiloPiloTiloTiloTiloTiloPiloLiloEbWzBtCiAg
ICAgIBtbMzg7NTs5N20g4paD4paFG1s0ODs1Ozk3beKWhiAgICAgICAgICAbWzBtG1szODs1Ozk3
beKWh+KWhuKWgxtbMG0KICAgIBtbMzg7NTs5N23iloHiloUbWzQ4OzU7OTdtG1szODs1OzYxbSAb
WzM4OzU7OTdtICAgICAgG1szODs1OzE0MG0gG1szODs1OzIzMW3iloHiloLiloPiloTiloTiloIb
WzM4OzU7MTAzbSAbWzM4OzU7OTdtICAbWzM4OzU7NjFtIBtbMG0bWzM4OzU7OTdt4paF4paBG1sw
bQogIBtbMzg7NTsyMzZtIBtbMzg7NTs5N23iloQbWzQ4OzU7OTdtG1szODs1OzYxbSAbWzM4OzU7
OTdtICAgICAgG1szODs1Ozk3bSAbWzM4OzU7MTAzbSAbWzQ4OzU7MjMxbRtbMzg7NTs5N23ilofi
lobilobiloTilbgbWzM4OzU7MjMxbSAgG1s0ODs1Ozk3beKWihtbMzg7NTs5N20gICAgG1szODs1
OzYxbSAbWzBtG1szODs1Ozk3beKWhBtbMG0KICAbWzM4OzU7OTdtG1s3beKWmBtbMjdtG1szODs1
Ozk3bRtbNDg7NTs5N20gICAgG1szODs1Ozk3bSAbWzM4OzU7MjMxbeKWheKWhhtbNDg7NTsyMzFt
ICAgICAgICAgICAgG1szODsyOzE0MzsxMzM7MTkxbeKWgRtbMzg7MjsxMzI7MTI4OzE5NG3iloEb
WzM4OzI7MTM0OzEyNzsxOTFt4paCG1szODsyOzEzMjsxMjQ7MTg5beKWghtbMzg7MjsxMzE7MTI1
OzE5Mm3iloEbWzM4OzI7MTQ3OzEzNTsxOTJt4paBG1swbQogICAgICAgG1szODsyOzEzNTsxMzI7
MTk3beKWgeKWg+KWheKWhxtbNDg7MjsxMzE7MTI4OzE5Nm0bWzM4OzI7MTMxOzEyOTsxOTdt4paF
G1s0ODsyOzEzMTsxMjk7MTk3bRtbMzg7MjsxMzE7MTI4OzE5Nm3iloTiloQbWzQ4OzI7MTMwOzEy
NzsxOTVtG1szODsyOzEyOTsxMjQ7MTk0beKWgxtbNDg7MjsxMjk7MTI1OzE5NG0bWzM4OzI7MTI4
OzEyMjsxOTNt4paEG1s0ODsyOzEyOTsxMjM7MTkzbRtbMzg7MjsxMjg7MTIwOzE5MW3iloQbWzQ4
OzI7MTI4OzEyMTsxOTJtG1szODsyOzEyNzsxMTg7MTkwbeKWhBtbNDg7MjsxMjk7MTIwOzE5MG0b
WzM4OzI7MDswOzBtIBtbMG0bWzM4OzI7MTMyOzEyMTsxOTBt4paHG1szODsyOzEzMDsxMTg7MTg4
beKWhRtbMzg7MjsxMzQ7MTIwOzE4OG3iloMbWzBtCiAgICAgG1szODsyOzEzMDsxMjg7MTk2beKW
@simonLeary42
simonLeary42 / fmt_color.py
Created January 22, 2025 02:51
like GNU `fmt` with ANSI color support
#!/usr/bin/env python3
import re
import sys
import string
MAX_LINE_LEN = 80
ANSI_ESCAPE_SEQUENCE = re.compile(r"\x1b\[[0-9;:]*?m")
ALL_ASCII_CHARS = {chr(i) for i in range(128)}
ALLOWED_CHARS = (ALL_ASCII_CHARS - set(string.whitespace)).union({" ", "\n"})
; Stewie Tweaks INI
; New options are generated when the game is launched
[INI]
; allow INIs in the Tweaks\INIs folder to overwrite the main INI
bMultiINISupport = 1
; show [SECTION] SETTING when viewing subsettings in tweaks' menu
import os
from contextlib import redirect_stdout
def stdout2str(lambda_func):
read_fd, write_fd = os.pipe()
with os.fdopen(write_fd, "w") as write_pipe:
with redirect_stdout(write_pipe):
lambda_func()
with os.fdopen(read_fd, "r") as read_pipe:
return read_pipe.read()
import re
import sys
import random
def replace_char(x):
if x.isalpha():
return random.choice("αβγδεζηθικλμνξοπρστυφχψω")
else:
return x
#!/bin/bash
set -euo pipefail
ssh_client_ip=$(echo $SSH_CLIENT | awk '{print $1}')
w_json="$(w --pids $USER | jc --w)"
if [ -z "$w_json" ]; then
echo "error: 'w --pids | jc --w' didn't print anything!"
exit 1
fi