Skip to content

Instantly share code, notes, and snippets.

@vadimkantorov
vadimkantorov / freetype2github.sh
Last active November 1, 2026 11:33
Clone FreeType into GitHub account
set -ex
# bash freetype2github.sh ssh.gitlab.freedesktop.org freetype freetype vadimkantorov
GITLABDOMAIN=$1
GITLABUSERNAME=$2
REPONAME=$3
GITHUBUSERNAME=$4
# Clone the repo from GitLab using the `--mirror` option.
# for conversion from Adobe Premier txt format to srt: https://gotranscript.com/subtitle-converter
# brew install ffmpeg-full # for libass
# bash ffmpeg_overlay_srt_subtitles.sh myvideo.mov # also uses myvideo.mov.srt
# extract audio for srt generation via Gemini
# ffmpeg -i $1 -map a:0 -c copy $1.m4a
# with semi-transparent background and white text
#ffmpeg -i $1 -vf "subtitles=$1.srt:force_style='OutlineColour=&H80000000,BorderStyle=4,BackColour=&H80000000,Outline=0,Shadow=0,MarginV=25,Fontname=Arial,Fontsize=10,Alignment=2'" -y $1_srt.mp4
@vadimkantorov
vadimkantorov / findsed.sh
Last active September 8, 2026 08:56
sed replace in files http with https
find . -type f -maxdepth 1 -name '*.md' -exec sed -i '' 's/http\:/https\:/g' {} ';'
# grep 'http\://' *.md
@vadimkantorov
vadimkantorov / leaflet_popup_screenshot.py
Last active August 1, 2026 19:03
Use Chrome headless to create a screenshot of LeafletJS map with a custom open marker popup
import argparse
import subprocess
import base64
parser = argparse.ArgumentParser()
parser.add_argument('--chrome-exe', default = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome')
parser.add_argument('--user-agent', default = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36')
parser.add_argument('--lang', default = 'en_EN')
parser.add_argument('--output-path', '-o', default = 'screenshot.png')
parser.add_argument('--html-path', default = 'test.html')
@vadimkantorov
vadimkantorov / regexisodate.py
Last active July 3, 2026 12:58
Python ISO8601 date (YYYY-MM-DD) regex and testing script, handling leap years
import datetime
import re
# https://regexlib.com/REDetails.aspx?regexp_id=3344&AspxAutoDetectCookieSupport=1
# http://stackoverflow.com/questions/3143070/javascript-regex-iso-datetime/7221570#7221570
re_iso8601date = r'^(?:(?=[02468][048]00|[13579][26]00|[0-9][0-9]0[48]|[0-9][0-9][2468][048]|[0-9][0-9][13579][26])\d{4}(?:(-|)(?:(?:00[1-9]|0[1-9][0-9]|[1-2][0-9][0-9]|3[0-5][0-9]|36[0-6])|(?:01|03|05|07|08|10|12)(?:\1(?:0[1-9]|[12][0-9]|3[01]))?|(?:04|06|09|11)(?:\1(?:0[1-9]|[12][0-9]|30))?|02(?:\1(?:0[1-9]|[12][0-9]))?|W(?:0[1-9]|[1-4][0-9]|5[0-3])(?:\1[1-7])?))?)$|^(?:(?![02468][048]00|[13579][26]00|[0-9][0-9]0[48]|[0-9][0-9][2468][048]|[0-9][0-9][13579][26])\d{4}(?:(-|)(?:(?:00[1-9]|0[1-9][0-9]|[1-2][0-9][0-9]|3[0-5][0-9]|36[0-5])|(?:01|03|05|07|08|10|12)(?:\2(?:0[1-9]|[12][0-9]|3[01]))?|(?:04|06|09|11)(?:\2(?:0[1-9]|[12][0-9]|30))?|(?:02)(?:\2(?:0[1-9]|1[0-9]|2[0-8]))?|W(?:0[1-9]|[1-4][0-9]|5[0-3])(?:\2[1-7])?))?)$'
for yyyy in range(1000, 3001):
for mm in range(1, 13):
for dd in range(1, 32):
@vadimkantorov
vadimkantorov / paypaldonate.html
Last active July 17, 2026 16:08
PayPal donation form primer (with preset amounts and custom amount) in pure HTML / CSS without any JavaScript or tracking pixels
<!DOCTYPE html>
<html lang="en">
<!--
- Modeled after PayPal Giving Fund donation form: https://www.paypal.com/fr/fundraiser/charity/4864486
- Supports preset donation amounts and custom amount
- Contains two HTML forms because cannot put in a single form radio preset amount input and text custom amount input
- Inlines in two copies of business email, currency code, item name (for https://russie-Libertes.org)
- Verification/tracking pixel must be used for method="post"
- Default preset amount is highlighted with a heart symbol
- Unique form ids must be used for several forms
@vadimkantorov
vadimkantorov / pyproject.toml
Last active April 3, 2026 15:02
Use released vllm with pytorch
# git clone https://gist.github.com/vadimkantorov/07a421f676f8af94457732f8e9127dde
# cd 07a421f676f8af94457732f8e9127dde
# uv venv
# uv sync
# source .venv/bin/activate # uv run python
# https://github.com/pytorch/pytorch/issues/160875#issuecomment-4183789164
# https://github.com/vllm-project/vllm/issues/24218
[build-system]
@vadimkantorov
vadimkantorov / html2xhtml.py
Last active April 2, 2026 12:30
Primer of html2xml converter in python using html.parser and xml.dom.minidom modules
# python html2xhtml.py test.html test.xhtml
import html.parser
import xml.dom.minidom
class HTMLToMinidom(html.parser.HTMLParser):
# https://developer.mozilla.org/en-US/docs/Glossary/Void_element
def __init__(self, void_elements = ('area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr')):
super().__init__()
self.doc = xml.dom.minidom.Document()
@vadimkantorov
vadimkantorov / ps.sh
Last active September 13, 2025 01:17
Various ps commands
alias cmdline='ps --no-headers -o comm,args -p'
cmdline 1
# can produce JSON, but without process args
alias notbrokenjson='ps --no-headers -o '\''{"pcpu": %C, "group": "%G", "PPID": %P, "user": "%U", "comm": "%c", "rgroup": "%g", "nice": "%n", "pid": %p, "pgid": %r, "etime": "%t", "ruser": "%u", "time": "%x", "tty": "%y", "vsz": %z}'\'' -p'
notbrokenjson 1 > notbroken.json
# does not remove escape sequences or quotes in args - this will break JSON format for some processes
alias brokenjson='ps --no-headers -o '\''{"pcpu": %C, "group": "%G", "PPID": %P, "user": "%U", "args": "%a", "comm": "%c", "rgroup": "%g", "nice": "%n", "pid": %p, "pgid": %r, "etime": "%t", "ruser": "%u", "time": "%x", "tty": "%y", "vsz": %z}'\'' -p'
brokenjson 1 > brokenjson.json
@vadimkantorov
vadimkantorov / pyproject.toml
Last active September 4, 2025 05:25
Install and pin nighly vllm using pyproject.toml and uv
# git clone https://gist.github.com/vadimkantorov/fe63f8628ff6cad460e934e1d7ed650b
# cd fe63f8628ff6cad460e934e1d7ed650b
# uv venv
# uv sync
# https://github.com/vllm-project/vllm/pull/20358#issuecomment-3247178818
# https://github.com/vllm-project/vllm/issues/9244
# https://github.com/astral-sh/uv/issues/8082
# https://github.com/vllm-project/vllm/issues/24126