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 / 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::
@sirkonst
sirkonst / gsdproxy.py
Created November 10, 2011 07:32 — forked from ncode/gsdproxy.py
gevent simple dynamic reverse proxy
#!/usr/bin/env python
from gevent import monkey
monkey.patch_all()
import sys
import redis
import urllib2
import traceback
from cgi import escape
# -- gsdproxy
@sirkonst
sirkonst / states.state.py
Created February 24, 2012 13:20
State of states module for salt (saltstack)
"""
State module
============
The state module for logical union of several states.
Available Functions
-------------------
@sirkonst
sirkonst / states.state.py
Created March 2, 2012 07:27
State of states module for salt (saltstack)
"""
State module
============
The state module for logical union of several states.
Available Functions
-------------------
@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:
@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
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 / 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)
@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 / .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"