Skip to content

Instantly share code, notes, and snippets.

@yeger00
yeger00 / safelog.py
Last active December 19, 2021 15:05
import logging
class SafeLog:
def __init__(self, log: logging.Logger):
self.log = log
self.safe = False
def __enter__(self):
self.safe = True
return self
@yeger00
yeger00 / postgres_lock_utils.sql
Last active September 5, 2021 07:00
Set of queries to work with postgres
-- Check for currently running queries
SELECT * FROM pg_stat_activity WHERE state = 'active';
-- Kill an active query
SELECT pg_cancel_backend(12345);
-- Kill an active query
SELECT pg_terminate_backend(12345);
-- Get locking and locked queries
@yeger00
yeger00 / Makefile
Last active January 31, 2021 13:56
Makefile
dependencies = $(foreach dependency, $(1), build-module-$(dependency))
module1_dependencies =
module2_dependencies = $(call dependencies, module1)
module3_dependencies = $(call dependencies, module2)
module4_dependencies = $(call dependencies, module1)
all_modules = $(call dependencies, module1 module2 module3 module4)
docker1_dependencies = $(call dependencies, module1)
docker2_dependencies = $(call dependencies, module2, module4)
@yeger00
yeger00 / container_wrapper.py
Created December 7, 2020 06:56
A class that wraps a docker image for easier work. Used manily for tests.
import docker
import time
import typing
class ContainerWrapper:
'''
A class that wraps a docker image for easier work. Used manily for tests.
'''
def __init__(self, image, environment, ports, is_continaer_up: typing.Callable[[], bool]):
@yeger00
yeger00 / utils.py
Created October 2, 2020 10:16
Set of Python utility functions
def to_type(o, new_type):
'''
Helper funciton that receives an object or a dict and convert it to a new given type.
:param object|dict o: The object to convert
:param Type new_type: The type to convert to.
'''
if new_type == type(o):
return o
else:
return new_type(**o
function md() {
if ! command -v pandoc >/dev/null 2>&1 ; then
echo "pandoc is requiered, but it's not installed. Aborting.";
return;
fi
if ! command -v lynx >/dev/null 2>&1 ; then
echo "lynx is requiered, but it's not installed. Aborting.";
return;
fi
#!/bin/bash
# This script prints the "version" of the repository.
# The defenition of version is:
# If there is a tag points to the current commit - the prefix will be the tag. If not, it will be the current commit.
# If the repository is dirty, it will add "-dirty" as suffix.
# Examples:
# Tag and not dirty: v1.2.3
# Tag and dirty: v1.2.3-dirty
# Not a tag and not dirty: 3cccdf4a163d0b9fea760d5de83ad2ed23dc938d
@yeger00
yeger00 / split_grep.py
Last active October 2, 2022 09:46
Receive regex expressions, reads from stdin, and split the output into different columns - each for every regex
#!/usr/bin/env python
from typing import List
import typer # pip install typer==0.6.1
import termios
import fcntl
import os
import struct
import sys
import re