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 / 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
@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 / 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():
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 / 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 / constants.py
Last active May 26, 2016 13:06
Easy define python constants type.
class Constants(type):
class _ConstantsBase(dict):
def __getattribute__(self, name):
try:
return self[name]
except LookupError:
raise AttributeError(name)
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 / skip_error.py
Last active May 24, 2016 11:42
Decorator skip_error
class skip_error(object):
def __init__(self, exception, fn=None, default=None):
self.exception = exception
self.fn = fn
self.default = default
def __enter__(self):
return self.default