Skip to content

Instantly share code, notes, and snippets.

View ddelange's full-sized avatar
💥
["translatio", "imitatio", "aemulatio"]

ddelange ddelange

💥
["translatio", "imitatio", "aemulatio"]
View GitHub Profile
@ddelange
ddelange / mp4_srt.py
Last active December 19, 2022 07:09
Mux multiple subtitle files into an mp4 file
# pip install sh pycountry
import re
from pathlib import Path
import pycountry
from sh import ffmpeg
def mux_mp4_subs(inp, outp, *subs, _cwd=None, **subs_map):
"""Mux multiple subtitle files into an mp4 file.
@ddelange
ddelange / playwright_github_stars_lists.py
Last active July 4, 2023 14:12
Scrape the GitHub Stars Lists for a user
#!/usr/bin/env python3
# $ pip install pandas playwright tabulate && python -m playwright install --with-deps webkit
# $ GITHUB_REPOSITORY_OWNER=octocat python playwright_github_stars_lists.py
import asyncio
import os
from contextlib import asynccontextmanager
import pandas as pd
from playwright.async_api import async_playwright
from playwright.async_api._generated import Browser, Locator
@ddelange
ddelange / kubetop.py
Last active March 15, 2023 10:08
kubetop - cluster resource monitoring
# View node and container resource requests, limits, and usage, grouped per node,namespace,pod,container
#
# Installation:
# pip install mapply pandas kubernetes sh
# brew install watch kubectl coreutils
#
# Usage:
# alias kubetop='watch -n4 python ~/Downloads/kubetop.py'
# kubetop
@ddelange
ddelange / executor.py
Last active March 9, 2025 15:18
Make a sync function async
import asyncio
from functools import wraps, partial
def run_in_executor(fn=None, *, executor=None):
"""Make a sync function async. By default uses ThreadPoolExecutor.
Args:
fn: Function to decorate.
executor: Executor pool to execute fn in.
@ddelange
ddelange / PR Memes and GIFs.md
Last active December 13, 2024 16:12
PR Memes and GIFs

Uploaded using the New Issue dialog (and its githubusercontent link copied from the Preview tab)

![obama-awards-obama-a-medal](https://user-images.githubusercontent.com/14880945/104736592-80303380-5743-11eb-8224-2bae4fab6f15.png)

obama-awards-obama-a-medal

![bike front flip](https://user-images.githubusercontent.com/14880945/104123855-bfc6dc00-534d-11eb-8772-50b19cccc10a.gif)

bike front flip

![adam handshake michelangelo](https://media4.giphy.com/media/QAIyzXKtQ9ENG/giphy.gif)

adam handshake michelangelo

@ddelange
ddelange / doccano_active_learning.py
Last active November 22, 2024 15:27
Doccano Sequence Labelling Active Learning
"""Interact with Doccano Sequence Labelling projects.
Trains on checked (approved) annotations, pushes back predictions for unchecked annotations.
### Notes
- Doccano might implement active learning themselves in the future: https://github.com/doccano/doccano/issues/191
- To support multilingual NER projects, split_sentence() below uses polyglot, which in turn requires PyICU.
@ddelange
ddelange / zipdir.py
Last active March 14, 2022 15:03
Zip/unzip a directory without absolute paths in the archive
#!/usr/bin/env python
import zipfile
from pathlib import Path
def zipdir(src, dest=None, glob='*', **kwargs):
"""Zip contents of src directory into dest.
Args:
src: source directory path-like
@ddelange
ddelange / translitcodec.py
Created March 27, 2020 11:13
Python transliterate / remove accents / normalize accents
import translitcodec
def print_variations(x):
print(x)
print(translitcodec.short_encode(x)[0])
print(translitcodec.long_encode(x)[0])
print_variations("Gesellschaft mit beschränkter Haftung")
print_variations("Société Privée à Responsabilité Limitée")
print_variations("Shoqëri me përgjegjësi të kufizuar")
@ddelange
ddelange / convert_ipynb_to_py.py
Created November 20, 2019 10:15
Convert iPython Notebook (.ipynb) to a Python file (.py) from CLI
"""Convert ipynb file to py file from CLI.
Usage:
python ./convert_ipynb_to_py.py [full input path] [full output path]
!! overwrites output path without warning if it exists !!
"""
import sys
import json
@ddelange
ddelange / review_assignment.py
Last active September 16, 2019 13:49
Review assignment and potentially override rejection
import boto3
import logging
import os
import pprint
import xmltodict
pp = pprint.PrettyPrinter(depth=3).pprint
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)