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:
nt-256color.ans | base64
ICAgICAgICAgIBtbMzg7NTs5N23iloHiloLiloPiloTiloTiloTiloTiloPiloLiloEbWzBtCiAg
ICAgIBtbMzg7NTs5N20g4paD4paFG1s0ODs1Ozk3beKWhiAgICAgICAgICAbWzBtG1szODs1Ozk3
beKWh+KWhuKWgxtbMG0KICAgIBtbMzg7NTs5N23iloHiloUbWzQ4OzU7OTdtG1szODs1OzYxbSAb
WzM4OzU7OTdtICAgICAgG1szODs1OzE0MG0gG1szODs1OzIzMW3iloHiloLiloPiloTiloTiloIb
WzM4OzU7MTAzbSAbWzM4OzU7OTdtICAbWzM4OzU7NjFtIBtbMG0bWzM4OzU7OTdt4paF4paBG1sw
bQogIBtbMzg7NTsyMzZtIBtbMzg7NTs5N23iloQbWzQ4OzU7OTdtG1szODs1OzYxbSAbWzM4OzU7
OTdtICAgICAgG1szODs1Ozk3bSAbWzM4OzU7MTAzbSAbWz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m▄[0;38:2:1:105:74:156m▄[0;38:2:1:104:72:155m▄[0;38:2:1:100:65:148m▄[0;38:2:1:95:56:140m▃[0;38:2:1:83:40:121m▃[0;38:2:1:76:37:110m▂
[0;38:2:1:75:38:108m▁[0;38:2:1:96:56:142m▃[0;38:2:1:107:81:159m▆[0;38:2:1:127:122:191;48:2:1:89:45:130m▅[0;38:2:1:131:129:197;48:2:1:131:128:196m▄▅[0;38:2:1:131:128:196;48:2:1:131:129:197m▗[0;38:2:1:130:126:195;48:2:1:130:128:196m▃[0;38:2:1:129:124:194;48:2:1:130:126:195m▃[0;38:2:1:128:122:193;48:2:1:129:125:194m▄[0;38:2:1:128:120:191;48:2:1:129:123:193m▄[0;38:2:1:128:122:192;48:2:1:127:119:190m▘[0;38:2:1:0:0:0;48:2:1:125:114:187m [0;38:2:1:126:115:188;48:2:1:94:57:139m▆[0;38:2:1:122:107:182;48:2:1:84:42:122m▅[0;38:2:1:101:71:149m▆[0;38:2:1:89:50:130m▃[0;38:2:1:68:35:97m▁
[0;38:2:1:75:37:108m▗[0;38:2:1:102:70:151m▅[0;38:2:1:128:123:192;48:2:1:98:58
@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