Skip to content

Instantly share code, notes, and snippets.

View thehesiod's full-sized avatar
🎯
Focusing

Alexander Mohr thehesiod

🎯
Focusing
View GitHub Profile
@thehesiod
thehesiod / 1pass_dups.py
Last active October 5, 2023 17:09
1password duplicate remover (alpha, only run in debugger with breakpoints everywhere *g*)
#!/usr/bin/env python3
import json
import subprocess
import sys
from concurrent.futures import ThreadPoolExecutor
import html
import dictdiffer
import iso8601
@thehesiod
thehesiod / async_worker_pool.py
Last active June 30, 2023 11:01
Asynchronous Worker Pool, allows for limiting number of concurrent tasks
import asyncio
from datetime import datetime, timezone
import os
def utc_now():
# utcnow returns a naive datetime, so we have to set the timezone manually <sigh>
return datetime.utcnow().replace(tzinfo=timezone.utc)
class Terminator:
pass
@thehesiod
thehesiod / MemTracer.py
Last active May 15, 2023 22:55
Memory Tracer
import tracemalloc
import os
import linecache
import wrapt
_TRACE_FILTERS = (
tracemalloc.Filter(False, "<frozen importlib._bootstrap>"),
tracemalloc.Filter(False, tracemalloc.__file__, all_frames=True), # needed because tracemalloc calls fnmatch
tracemalloc.Filter(False, linecache.__file__),
tracemalloc.Filter(False, os.path.abspath(__file__), all_frames=True), # since we call weakref
@thehesiod
thehesiod / freeze_time.sql
Created May 20, 2020 09:41
fake/mock now on postgres DB
-- inspiration from https://dba.stackexchange.com/questions/69988/how-can-i-fake-inet-client-addr-for-unit-tests-in-postgresql/70009#70009
CREATE SCHEMA if not exists override;
create table if not exists override.freeze_time_param_type
(
param_type text not null primary key
);
insert into override.freeze_time_param_type values ('enabled'), ('timestamp'), ('tick') on conflict do nothing;
@thehesiod
thehesiod / watchdog.py
Created May 19, 2022 15:28
python sync watchdog
import asyncio
import faulthandler
import warnings
from pathlib import Path
import io
from typing import Optional
# This is how often we'll trigger our callback to measure blockage
_MIN_RESOLUTION = 0.1
@thehesiod
thehesiod / rheem_usage.py
Last active January 20, 2023 22:01
Rheem Water Heater Energy Usage Calculator
import asyncio
import argparse
from collections import defaultdict
from datetime import date, timedelta
import logging
from typing import Dict
from pprint import pprint
from pyeconet import EcoNetApiInterface
from pyeconet.equipment import EquipmentType
@thehesiod
thehesiod / gather_cancel_children_on_exception.py
Last active September 27, 2022 08:55
asyncio cancel all tasks on first task's exception
import asyncio
import logging
from typing import List
def _ignore_task_exception(task: asyncio.Future, logger: logging.Logger):
# noinspection PyBroadException
try:
task.result()
except BaseException:
@thehesiod
thehesiod / file_sync.py
Created May 12, 2022 02:16
async file syncer
import asyncio
import os
from pathlib import Path
from typing import Dict, Optional
import logging
import shutil
from functools import partial
import hashlib
import dataclasses
import asyncio
import os
import time
import logging
from multiprocessing import Process, Queue
from queue import Empty
import botocore.session
from botocore.credentials import Credentials, CredentialResolver, CredentialProvider, AssumeRoleProvider
@thehesiod
thehesiod / android_dcim_cleanup.py
Last active December 6, 2020 20:06
Delete Empty Android DCIM folders
# requires webdav connection (see WebDAV Server app, and ensure port is not 8080)
from pathlib import Path
import shutil
def main():
cam_path = Path('//192.168.1.186@8081/DavWWWRoot/DCIM/Camera')
for idx, item in enumerate(cam_path.iterdir()):
if idx % 100 == 0:
print(f"Processing folder {idx}")