Skip to content

Instantly share code, notes, and snippets.

View kgantsov's full-sized avatar
🇺🇦

Kostiantyn Hantsov kgantsov

🇺🇦
  • iconik.io
  • Stockholm, Sweden
View GitHub Profile
@kgantsov
kgantsov / kubectl_top_pods_container_stats.py
Last active March 25, 2025 08:06
Memory usage statistics (min, max, mean, 95th percentile) for Kubernetes pods grouped by container name
import argparse
import subprocess
import statistics
from collections import defaultdict
from typing import Union
def run_kubectl_top(
all_namespaces: bool = False,
@kgantsov
kgantsov / time_from_uuid1.py
Created April 11, 2022 07:23
time_from_uuid1.py
from datetime import datetime
from datetime import timedelta
from uuid import UUID
def time_from_uuid1(u: str) -> datetime:
return datetime(1582, 10, 15) + timedelta(microseconds=UUID(u).time // 10)
fastapi==0.70.0
gino==1.0.1
pytest==6.2.5
pytest-asyncio==0.16.0
requests==2.26.0
@kgantsov
kgantsov / find_env_folders.sh
Created June 11, 2021 11:40
Find python's virtualenv directories and display them along with size
# simple script that finds all python virtualenv folders and shows how much
# space they are taking byt running `du -sh` command on each of the found directory
sudo find ~ -type d \( -name env -o -name venv \) -exec du -sh {} \; 2>/dev/null
- What do Etcd, Consul, and Zookeeper do?
- Service Registration:
- Host, port number, and sometimes authentication credentials, protocols, versions
numbers, and/or environment details.
- Service Discovery:
- Ability for client application to query the central registry to learn of service location.
- Consistent and durable general-purpose K/V store across distributed system.
- Some solutions support this better than others.
- Based on Paxos or some derivative (i.e. Raft) algorithm to quickly converge to a consistent state.
- Centralized locking can be based on this K/V store.
@kgantsov
kgantsov / covid-19-dashboard-styles.markdown
Last active September 24, 2020 10:33
covid-19-dashboard-styles
# Usage: echo '{"a": [], "b": "c"}' | jsonify
alias jsonify="python -m json.tool | pygmentize -l json"
# Usage: whoseport 8888
whoseport () {
lsof -i ":$1" | grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn} LISTEN
}
#!/usr/bin/python
import os
import usb
import telebot
from temperusb import TemperDevice
TEMP_VENDOR_ID = 0x0c45
TEMP_PRODUCT_ID = 0x7401
@kgantsov
kgantsov / revoke_celery_tasks.py
Created January 2, 2019 11:22
Helper functions that revokes celery tasks by name and ID
from celery.task.control import revoke
from celery.task.control import inspect
def revoke_tasks_by_name(task_name, worker_prefix=''):
"""
Revoke all tasks by the name of the celery task
:param task_name: Name of the celery task
:param worker_prefix: Prefix for the worker