Skip to content

Instantly share code, notes, and snippets.

View sirkonst's full-sized avatar

Konstantin vz'One Enchant sirkonst

View GitHub Profile
@sirkonst
sirkonst / shell.nix
Last active October 6, 2022 08:19
Nix shell environment for development python project (with virtualenv and IPython support)
with import <nixpkgs> { };
let
pythonPackages = python37Packages;
pythonVenvDir = ".local/${pythonPackages.python.name}";
envPackages = [
gettext
gitMinimal
];
preInstallPypiPackages = [
@sirkonst
sirkonst / docker-prune.service
Created November 22, 2018 12:25
Remove unused docker resources with systemd (service and timer)
[Unit]
Description=Remove unused docker resources
Documentation=https://docs.docker.com/v17.09/engine/admin/pruning/
After=docker.service
[Service]
Type=oneshot
ExecStart=/usr/bin/docker system prune -f --filter "until=744h"
ExecStart=/usr/bin/docker volume prune -f
vzlist -o ctid -H | xargs -n 1 -I {} sh -c "vzctl stop {} && vzctl destroy {}"
@sirkonst
sirkonst / .gitconfig
Last active August 9, 2017 06:50
git cleanup -- remove all already merged branches (excludes: master, develop, release)
[alias]
cleanup = "!git branch --merged | grep -v '\\*\\|master\\|develop\\|release' | xargs -n 1 git branch -d"
@sirkonst
sirkonst / config.fish
Last active March 31, 2022 20:56
fish config for pyenv (~/.config/fish/config.fish)
set PYENV_ROOT $HOME/.pyenv
set -x PATH $PYENV_ROOT/bin $PATH
status --is-interactive; and . (pyenv init -|psub)
status --is-interactive; and . (pyenv virtualenv-init -|psub)
set -x VIRTUAL_ENV_DISABLE_PROMPT 1
@sirkonst
sirkonst / kill_thread.py
Created September 15, 2016 08:11
Kill thread in python
import ctypes
import threading
import time
# inspired by https://github.com/mosquito/crew/blob/master/crew/worker/thread.py
def kill_thread(
thread: threading.Thread, exception: BaseException=KeyboardInterrupt
) -> None:
if not thread.isAlive():
@sirkonst
sirkonst / closure_and_corrutines.py
Last active August 11, 2016 11:29
Сlosure with asyncio corrutines isn't async-safe
import asyncio
from functools import partial
async def process(d):
print('process', d)
async def amain(loop):
data = range(2)
@sirkonst
sirkonst / underscore_bug.py
Last active December 29, 2015 11:41
How to get segmentation fault with crazy __ (python 2 and 3)
__obj = object()
# uncomment for fix:
# _Class__obj = __obj
def func():
print('func:', __obj)
class Class:
class Namespace:
__slots__ = '_Namespace__names'
def __init__(self, **items):
self.__names = dict(**items)
def __setattr__(self, key, value):
if key in self.__slots__:
super().__setattr__(key, value)
@sirkonst
sirkonst / combinations_dict.py
Last active September 18, 2015 09:58
Generates all possible combinations of values for dictionary (useful for tests)
from itertools import combinations
def combinations_dict(data):
"""
Generates all possible combinations of values for dictionary.
At the entrance you can pass either dictionary or list of tuples.
Examples::