Skip to content

Instantly share code, notes, and snippets.

View addam's full-sized avatar

Addam Dominec addam

View GitHub Profile
@addam
addam / lock.js
Created March 6, 2024 11:14
Semaphore for node.js
function createLock() {
const clients = new Map()
function nop() {
}
const lock = (id) => {
const waiting = clients.get(id)
if (!waiting) {
const queue = []
@addam
addam / feather_dilate.py
Created August 25, 2023 12:32
Dilate a stack of images with feather kernel
def feather_dilate(stack: np.ndarray, radius=20):
"""Feather dilate a stack of images
stack has dimensions: [image_id, x, y]
The result is similar to dilation but with feather edges"""
ms = max_steepness
msq = ms * 2**0.5
for x in range(1, stack.shape[2]):
stack[:,:, x] = (np.maximum(stack[:,:, x], stack[:,:, x-1] - ms))
for x in range(stack.shape[2]-2, -1, -1):
@addam
addam / stream_docker_stats.py
Last active July 7, 2023 08:40
Record Docker memory usage in CSV format
import subprocess
import time
from sys import argv
run_args = "docker stats --format {{.MemUsage}}".split()
if len(argv) > 1:
run_args.append(argv[1])
background = subprocess.Popen(run_args, stdout=subprocess.PIPE)
units = {'Ki': 1e3, 'Mi': 1e6, 'Gi': 1e9, 'Ti': 1e12}
print("timestamp_seconds", "memory_bytes", flush=True)
@addam
addam / qrclipboard.py
Created May 29, 2023 09:34
Read image from the clipboard and decode its qr code
#!/usr/bin/python3
from PyQt5.QtWidgets import QApplication, QLabel, QMessageBox
from pyzbar import pyzbar
import numpy as np
def qimage2mat(qimage):
qimage.convertToFormat(4)
ptr = qimage.bits()
ptr.setsize(qimage.byteCount())
arr = np.array(ptr).reshape([qimage.height(), qimage.width(), 4])
@addam
addam / normalize_background.py
Created April 3, 2023 10:48
robust fit 2D polynomial to an image. Given a photo of a paper, makes it perfectly white.
from sys import argv
import cv2
import numpy as np
import scipy
iterations = 2
def grid(shape):
y = np.linspace(0, 1, shape[0])
x = np.linspace(0, 1, shape[1])
@addam
addam / classifier.py
Created March 30, 2022 14:51
Simple image classifier using Opencv and a Bag of Words model
import cv2
import numpy as np
from tkinter import Tk
from tkinter.filedialog import askopenfilename
descriptors = []
# evaluate the similarity between two point clouds
# enormous robustness against outliers is necessary
def score(a, b):
@addam
addam / classifier.html
Last active April 8, 2022 11:50
Webpage for detecting portions of same content in images using Opencv.js and a Bag of Words model
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title>Classifier</title>
<script>
let descriptors = [];
qs = (sel) => document.querySelector(sel);
@addam
addam / timer.html
Created February 19, 2022 09:52
simple countdown timer on local webpage
<html>
<meta charset=utf-8>
<title>Timer</title>
<style>
@keyframes blinker {
50% {
opacity: 0;
}
}
body {
@addam
addam / sorter.html
Last active March 30, 2022 13:05
html tool for manual sorting photos on local disk
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="list.js"></script>
<script>
// generate list.js from images in current directory:
// (echo 'imageList = ['; ls *.{jpg,jpeg,JPG,JPEG} | sed -E 's/(.*)/"\1",/p'; echo ']') > list.js
// generate list.js from images in subdirectories of the current one:
// (echo 'imageList = ['; ( for d in *; do ls "$d"/*.{jpg,jpeg,JPG,JPEG}; done) | sed -E 's/(.*)/"\1",/p'; echo ']') > list.js

Keybase proof

I hereby claim:

  • I am addam on github.
  • I am addaddam (https://keybase.io/addaddam) on keybase.
  • I have a public key whose fingerprint is 796C 5FBD 3DA7 2B1F BBF5 CF8C E999 6060 AB12 D85C

To claim this, I am signing this object: