Skip to content

Instantly share code, notes, and snippets.

@kirpit
kirpit / fields_dict.py
Last active December 16, 2015 16:08
python dictionary with key requirements
#! /usr/bin/env python
from abc import ABCMeta
class FieldsDict(dict):
__metaclass__ = ABCMeta
FIELDS = None
REQUIRED = None
def __init__(self, seq=None, **kwargs):
@kirpit
kirpit / bridge.py
Created September 13, 2012 10:29 — forked from pazdera/bridge.py
Example of `bridge' design pattern in Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Example of `bridge' design pattern
# This code is part of http://wp.me/p1Fz60-8y
# Copyright (C) 2011 Radek Pazdera
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
@kirpit
kirpit / bash.py
Last active March 17, 2023 06:29
Enables to run subprocess commands in a different thread with TIMEOUT option!
#! /usr/bin/env python
import threading
import subprocess
import traceback
import shlex
class Command(object):
"""
Enables to run subprocess commands in a different thread with TIMEOUT option.
@kirpit
kirpit / release_info.py
Created August 28, 2011 13:07
Returns first level namespace (package import name) of a setuptools distribution
#! /usr/bin/env python2.7
'''
http://stackoverflow.com/questions/7184375/how-to-find-import-name-of-any-package-in-python
'''
import distutils.core
import sys
import os