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 / Installing PyICU, libpostal, pypostal on Mac OS X 10.14+.md
Last active August 9, 2024 12:03
Installation instructions for libicu-dev, PyICU, libpostal, pypostal on Mac OS X 10.14+

Installing PyICU, libpostal, pypostal on Mac OS X 10.14+

libicu-dev (PyICU dependency)

brew uninstall --ignore-dependencies icu4c
brew install pkg-config icu4c  # keg-only
@ddelange
ddelange / airflow_slack_notifications.md
Last active November 16, 2023 16:57
Airflow Slack notifications

Airflow Slack notifications

Installation

Make sure slackclient v1.3.1 is installed (for apache-airflow 1.10).

pip install -U "apache-airflow[slack,...]"
@ddelange
ddelange / kubectl_plug_play.md
Last active December 22, 2023 13:59
kubebash kubelogs kubebranch

Kubectl Plug & Play Extensions

  • interactive shell -- kubebash <namespace> <deployment>
  • live colored logs streaming -- kubelogs <namespace> <deployment>
  • deployments dockertag table -- kubebranch <namespace> [<partial deployment name>]

A customized subset of kubectl commands. See also: official kubectl cheatsheet

tl;dr

I just want plug&play bash functions
@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)
@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 / 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 / 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 / doccano_active_learning.py
Last active January 13, 2021 09:26
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 / PR Memes and GIFs.md
Last active October 28, 2024 09:07
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 / executor.py
Last active October 11, 2024 14:16
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.