Skip to content

Instantly share code, notes, and snippets.

View andreycizov's full-sized avatar

Andrey Cizov andreycizov

  • London
View GitHub Profile
@andreycizov
andreycizov / threadprocesspoolexecutor.py
Created April 4, 2016 13:53
concurrent.futures ThreadProcessPoolExecutor
import multiprocessing
import os
from concurrent.futures import ProcessPoolExecutor
from concurrent.futures.process import _process_worker as _old_process_worker
from threading import Thread
_thread_worker = _old_process_worker
def _process_worker(max_threads, call_queue, result_queue):
@andreycizov
andreycizov / mp_coverage.py
Last active May 27, 2019 08:40
Enabling Python 3.5 Coverage support for multiprocessing Pool
import logging
import os
from multiprocessing.pool import Pool as OrigPool
from coverage import Coverage
from multiprocessing.context import Process, DefaultContext, _concrete_contexts
logger = logging.getLogger(__name__)

Keybase proof

I hereby claim:

  • I am andreycizov on github.
  • I am andreycizov (https://keybase.io/andreycizov) on keybase.
  • I have a public key ASCxzilikrO1Fkzwv-ciT5kJUghPemSNx2lcPjjdAS555go

To claim this, I am signing this object:

@andreycizov
andreycizov / trc.py
Created July 28, 2018 15:17
trc.py: Python automatic logger generation from the calling function (> 3.6)
def trc(postfix: Optional[str] = None) -> logging.Logger:
"""
Automatically generate a logger from the calling function
:param postfix: append another logger name on top this
:return: instance of a logger with a correct path to a current caller
"""
x = inspect.stack()[1]
@andreycizov
andreycizov / pulseaudio.service
Created September 12, 2018 11:36
Raspberry PI pulseaudio systemd daemon definition with proper restarts
# /etc/systemd/system/pulseaudio.service
[Unit]
Description=PulseAudio system server
# make sure we start after the network is available
After=network.target network-online.target
Wants=network-online.target
[Service]
@andreycizov
andreycizov / mousemon.sh
Last active July 30, 2023 03:18
mousemon.sh - Disable mouse when locking the screen Ubuntu
#!/bin/bash
# mousemon.sh - Andrey Cizov (acizov@gmail.com) 2018 (no license applied, free to use on any terms)
#
# Sometimes you'd like to have more control on what toggles the screensaver on your Ubuntu.
# In my scenario the mouse is too sensitive, so whenever I lock the screen subsequently turning
# off the monitors - it's too easy to turn them back on by accidentally touching the mouse.
# Even mildly loud bass is enough to do so.
# This script disables a selected device whenever the lock screen is activated.
@andreycizov
andreycizov / dunst-slack.sh
Created December 11, 2019 21:06
Enable desktop notifications trigger urgent flag for your Slack running in Linux via Dunst filters
#!/bin/sh -ex
# THIS SCRIPT ASSUMES YOU DON'T HAVE A CUSTOM DUNST SETUP IN ~/.config/dunst/dunstrc!!!!!!
# https://geekoverdose.wordpress.com/2019/08/01/i3-window-manager-selectively-make-any-notification-urgent-urgency-flag-to-highlight-the-workspace/
mkdir -p ~/bin
DUNST=~/bin/dunst-urgent-notification
cat >$DUNST <<BEGIN
@andreycizov
andreycizov / file.sh
Last active December 25, 2019 15:09
Run all gnome-settings-daemons
#!/bin/sh
env XDG_CURRENT_DESKTOP=GNOME gnome-control-center
ls /usr/lib/gnome-settings-daemon | parallel -j 0 /usr/lib/gnome-settings-daemon/{}
@andreycizov
andreycizov / decrypt_chrome_cookies_linux.py
Last active July 10, 2020 14:06
Extract Chrome Cookies on Linux using Python
import hashlib
import os
import sqlite3
import yaml
from Crypto.Cipher import AES
def extract_cookie(domain_name) -> bytes:
with sqlite3.connect(os.path.expanduser('~/.config/google-chrome/Default/Cookies')) as conn:
cursor = conn.cursor()
@andreycizov
andreycizov / trace_return.py
Created December 1, 2020 11:24
Python log the lines which returned the value in a callable
def trace_return(pretty_printer):
def decorator(fun):
def decorated(*args, **kwargs):
import sys
import inspect
last_line = None
entered = False
def tracer(frame, event, arg=None):