Skip to content

Instantly share code, notes, and snippets.

View jonashaag's full-sized avatar

Jonas Haag jonashaag

View GitHub Profile
@jonashaag
jonashaag / Use macOS OCR engine from Python.md
Last active February 21, 2025 08:09
Use macOS OCR engine from Python

macOS Live Text has a very good quality/speed tradeoff.

Compared to Tesseract, it has much higher quality and is up to 3x as fast.

import json
import sqlite3
repodata = json.load(open("497deca9.json"))
COLS = 'filename, build, build_number, depends, license, license_family, md5, name, sha256, size, subdir, timestamp, version'.split(', ')
db = sqlite3.connect("497deca9.sqlite")
db.execute("create table repodata ({}, primary key (filename))".format(','.join(COLS)))
@jonashaag
jonashaag / worksteal.py
Last active November 29, 2024 11:09
Python ThreadPoolExecutor Work Stealing
import concurrent.futures.thread as _thread_impl
import threading
import time
import weakref
from concurrent.futures import Future
class WorkStealThreadPoolExecutor(_thread_impl.ThreadPoolExecutor):
"""A ThreadPoolExecutor that supports work stealing.
@jonashaag
jonashaag / tesseract-finetune.md
Last active August 13, 2024 02:38
Tesseract LSTM fine-tuning how-to
  1. Download lots of fonts (eg., .ttf files)
  2. git clone https://github.com/tesseract-ocr/tesstrain/
  3. git clone https://github.com/tesseract-ocr/langdata_lstm
  4. Install Tesseract
  5. Generate training data:
    cd src
    python -m tesstrain \
      --langdata_dir /path/to/langdata_lstm \
      --linedata_only \
    
@jonashaag
jonashaag / enum_with_label.py
Last active August 5, 2024 11:19
Python Enum with label / verbose name / description
import enum
class EnumWithDisplayName(enum.Enum):
def __new__(cls, value, name=None):
if not hasattr(cls, "_value_to_display_name"):
cls._value_to_display_name = {}
cls._display_name_to_value = {}
if name is not None:
if value in cls._value_to_display_name:
@jonashaag
jonashaag / realapp.py
Created December 7, 2010 14:03
WSGI middleware that automatically reloads the wrapped app if it changes
def app(env, start_response):
start_response('200 ok', [])
return 'hello\n'
@jonashaag
jonashaag / prompt.txt
Last active June 3, 2024 11:12
OVH AI Endpoint failure
I'm going to present you with a piece of text. Please classify it according to the classes outlined after the text.
The text:
"""
When should you choose MongoDB over a relational database management system (RDBMS) like MySQL?
By Dimitri Fague / 2024-05-23 / Databases, DBaaS, MongoDB, OVHcloud, Public Cloud
Of all the non-relational database engines (NoSQL) that have emerged in the last decade, MongoDB is without a doubt the most widely used. Source-available, powerful, flexible and scalable, MongoDB covers a wide range of use cases. Many, including startups, choose it to ensure they are not limited in their technological choices, so they can scale and adapt to different use cases. The possibility of switching from MySQL to MongoDB might come up when updating or revamping an existing app. So, let’s see when this switch might be relevant, and why using the MongoDB service managed by OVHcloud could be the ideal option.
The flexibility of the NoSQL data model
@jonashaag
jonashaag / gist:7ca5b19abf537a447d0de1b923043f45
Last active March 28, 2024 12:20
T60/RT60, C50/C80, D in Python
import librosa
from scipy.signal import butter, lfilter
SR = 8000
NFFT = 256 # change ~proportionally to SR
def butter_bandpass(lowcut, highcut, fs, order=5):
nyq = 0.5 * fs
low = lowcut / nyq
@jonashaag
jonashaag / aws_fargate_docker_application_load_balancer_without_public_ip.md
Last active March 14, 2024 23:34
AWS Fargate Docker Application Load Balancer Howto (without public IP)

AWS Fargate Docker Simple Deployment Setup with SSL termination

How to:

  • create a Docker-based AWS Fargate/ECS deployment
  • without the Docker containers having a public IP
  • with an Application Load Balancer as reverse proxy / SSL termination proxy sitting in front of the containers

For Fargate/ECS to be able to access your Docker images hosted on ECR (or somewhere else) you'll have to allow outbound internet access to the Fargate subnets. Here's how you do it.

@jonashaag
jonashaag / xkcdpass.sh
Created February 21, 2024 10:17
XKCD password
curl -L https://raw.githubusercontent.com/redacted/XKCD-password-generator/master/xkcdpass/static/eff-long \
| sort -R \
| head -n 5 \
| tr '\n' -