Skip to content

Instantly share code, notes, and snippets.

View paiv's full-sized avatar
🇺🇦
StandWithUkraine

Pavel Ivashkov paiv

🇺🇦
StandWithUkraine
View GitHub Profile
@paiv
paiv / png_tiny.py
Last active March 5, 2023 11:18
TinyPNG command line
#!/usr/bin/env python
import tinify # https://tinypng.com/developers/reference/python
import tomllib
from pathlib import Path
def main(input, output, background):
if output is None:
output = input
with open('.env', 'rb') as fp:
@paiv
paiv / analyze.py
Created February 26, 2023 10:53
AppleKeyboardLayouts.bundle structure analysis
#!/usr/bin/env python
import string
import struct
import subprocess
from pathlib import Path
# https://developer.apple.com/documentation/coreservices/uckeyboardlayout
# /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/Headers/UnicodeUtilities.h
_DefaultBundle = Path('/System/Library/Keyboard Layouts/AppleKeyboardLayouts.bundle')
@paiv
paiv / US.keylayout
Last active February 26, 2023 11:14
English US keyboard layout macOS 12 (ABC.keylayout, US.keylayout)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE keyboard SYSTEM "file://localhost/System/Library/DTDs/KeyboardLayout.dtd">
<!--
Data generated Sun Feb 26 12:35:43 2023
Generated by kluchrtoxml build 203
-->
<keyboard group="126" id="0" name="U.S." maxout="2">
@paiv
paiv / readme.txt
Created October 25, 2022 16:00
Wordle game
usage: wordle.py [-h] [-n N] [--word WORD] wordlist
positional arguments:
wordlist word list file
options:
-h, --help show this help message and exit
-n N, --max-attempts N
maximum attempts
--word WORD play this word
@paiv
paiv / mdtoc.py
Last active March 4, 2023 04:11
Markdown ToC generator
#!/usr/bin/env python
import re
def main(infile, hmin, hmax):
'Spec: https://kramdown.gettalong.org/converter/html.html'
text = infile.read()
rx = re.compile(r'^(#+)[ \t]+(.*?)\s*$', re.M)
rl = re.compile(r'^[\W\d]+')
ru = re.compile(r'[^\w\s-]+|_')
@paiv
paiv / kilim.ipynb
Created April 4, 2021 18:39
Generated bit-textures
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@paiv
paiv / mazegen.ipynb
Created January 14, 2021 16:31
maze generation
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@paiv
paiv / keyboard-non-us-remap-tilde.sh
Created February 3, 2020 14:56
macOS non-US keyboard remap § to `
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000035}]}'
@paiv
paiv / modinv.py
Last active August 4, 2021 08:11
modular multiplicative inverse
def modinv(n, mod):
t, w, r = 0, 1, mod
while n:
(q, n), r = divmod(r, n), n
t, w = w, t - q * w
if r > 1: raise Exception('not invertible ' + repr(n))
if t < 0: t += mod
return t
@paiv
paiv / set-keyrepeat-on.sh
Created February 14, 2019 15:51
macOS set keyboard key repeat instead of accented special characters
defaults write -g ApplePressAndHoldEnabled -bool NO