Skip to content

Instantly share code, notes, and snippets.

View p7k's full-sized avatar
🏠
Working from home

Pavel Katsev p7k

🏠
Working from home
View GitHub Profile
@p7k
p7k / voluptuous.xor.py
Created May 23, 2018 04:56
xor gate in voluptuous
def xor(fields, group_name):
"""Creates an Exclusive OR (XOR) logical gate voluptuous schema.
see https://github.com/alecthomas/voluptuous/issues/126
:param fields: fields comprising the exclusive group.
:type fields: Dict[str, Schema]
:param group_name: exclusive group identifier.
:type group_name: str
:returns: XOR gated voluptuous schema.
"""Translate a Tandem Repeat Finder file into a bed file containing
annotated repeat intervals.
> This file is a text file which contains the same information, in the same
order, as the summary table file, plus consensus pattern and repeat sequences
http://tandem.bu.edu/trf/trf.definitions.html#table
"""
from __future__ import division
@p7k
p7k / gist:4238388
Created December 8, 2012 03:02
greenlet throttling decorator | rate limiting gevent | with semaphores
from functools import wraps
from timeit import default_timer
import gevent
from gevent.queue import Queue
def gevent_throttle(calls_per_sec=0):
"""Decorates a Greenlet function for throttling."""
interval = 1. / calls_per_sec if calls_per_sec else 0
def decorate(func):
blocked = [False] # has to be a list to not get localised inside the while loop