Skip to content

Instantly share code, notes, and snippets.

View martin-kokos's full-sized avatar
💭
Looking for collaboration

martin-kokos martin-kokos

💭
Looking for collaboration
View GitHub Profile
@martin-kokos
martin-kokos / opencv_shared_enum_dict.md
Last active May 30, 2025 07:25
OpenCV shared option enum space

OpenCV functions use argument to modify their behavior. These arguments are integers which have special meaning, also called enums. These enums share the same integer space. You can sometimes see this in the wild and in docs that people use nondescript numbers as options when calling a function (even without keywords) eg. cv2.putText(img, "yolo", (10, 20), 0, 1, (255, 255, 255), 1, 2). Due to this it is possible to set the wrong option to the wrong funciton and OpenCV he no way to check for this (not that it does much checking).

For example the following example unexpectedly opens the image in grayscale mode because cv2.ROTATE_180 is int(0) and that is interpreted in this function as cv2.IMREAD_GRAYSCALE (sometimes the prefix of the option is not obvious):

img = cv2.imread('myimage.jpg', cv2.ROTATE_180)

(Sometimes, options can be combined by for more "fun" just like bitmasks - by adding them up)

❌ FAIL: torch=2.1.0 torchvision=0.1.6 (exit=1)
❌ FAIL: torch=2.1.0 torchvision=0.1.7 (exit=1)
❌ FAIL: torch=2.1.0 torchvision=0.1.8 (exit=1)
❌ FAIL: torch=2.1.0 torchvision=0.1.9 (exit=1)
❌ FAIL: torch=2.1.0 torchvision=0.2.0 (exit=1)
❌ FAIL: torch=2.1.0 torchvision=0.2.1 (exit=1)
❌ FAIL: torch=2.1.0 torchvision=0.2.2 (exit=1)
❌ FAIL: torch=2.1.0 torchvision=0.2.2.post2 (exit=1)
❌ FAIL: torch=2.1.0 torchvision=0.2.2.post3 (exit=1)
❌ FAIL: torch=2.1.0 torchvision=0.9.1 (exit=1)
@martin-kokos
martin-kokos / mini_metrics.md
Last active April 22, 2025 09:09
Mini metrics server setup VictoriaMetrics (Datadog-like)

This is a very minimal setup how to achieve a minimal metrics server for a small project or an embedded setup. Install VictoriaMetrics. https://docs.victoriametrics.com/quick-start/#starting-vm-single-from-a-binary

Install

Essentially:

VM_VERSION="v1.112.0"
wget -O /tmp/victoria-metrics.tar.gz "https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/${VM_VERSION}/victoria-metrics-linux-arm64-${VM_VERSION}.tar.gz"
sudo tar -xvf /tmp/victoria-metrics.tar.gz -C /usr/local/bin
sudo useradd -s /usr/sbin/nologin victoriametrics || true
@martin-kokos
martin-kokos / distcc_ubuntu.md
Last active June 1, 2024 09:58
Install gcc-14 and distcc on Ubuntu

Install gcc

apt install software-properties-common  # installs apt-add-repository
# apt-add-repository ppa:ubuntu-toolchain-r/test
apt-add-repository universe
apt update
apt install gcc-14 g++-14
ll /usr/bin/gcc-14
ll /usr/bin/g++-14
update-alternatives --display gcc
@martin-kokos
martin-kokos / task_manager.py
Last active January 8, 2021 14:40
Simple multiprocessing task manager
'''
If the tasks are inequally sized, it may happen with starmap and similar schedulers
which schedule tasks ahead of time, that some workers are lucky and finish early and some unlucky
and finish much later having the effect of the task batch using all CPU cores at first,
but then lucky workers finishing and core sitting idle.
This task manager serves as an example on how to have workers fetch tasks from a Queue.
Joblib, Pool.starmap or something else might be better, but maybe this is useful.
'''
# Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
JAVA_ANT_ENCODING=UTF-8
ESVN_REPO_URI="https://josm.openstreetmap.de/svn/trunk"
inherit eutils java-pkg-2 java-ant-2 subversion desktop
@martin-kokos
martin-kokos / kravi_hora_server.py
Last active August 31, 2020 18:48
Kravi hora occupancy provider
'''
Provides occupancy number http://localhost:8080/kravi_hora
'''
import logging
import re
import requests
from bs4 import BeautifulSoup
from aiohttp import web
@martin-kokos
martin-kokos / Webexpo 2019.md
Last active June 24, 2021 15:37
Webexpo 2019
@martin-kokos
martin-kokos / advent.py
Last active December 21, 2018 13:35
Advent countdown
import datetime as dt
from time import sleep as s
curr_date = dt.datetime.now().replace(month=11,day=27)
class Candles(list):
def __repr__(self):
items = ['\N{CANDLE}' if i else '_' for i in self]
return '[{items}]'.format(items=', '.join(items))
@martin-kokos
martin-kokos / oneliner_sed_in_python.sh
Last active December 6, 2018 13:50
When you are unable to port the RegExp to sed
cat myfile | python3 -c "expr='YOUR_REGEXP'; import sys; import re; [print(match) for match in re.findall(expr, ''.join(sys.stdin.readlines()))]"