This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
"""Interface to a dict stored as json, useful for shell scripts.""" | |
import argparse | |
import json | |
parser = argparse.ArgumentParser(description="set/list/get dict contents") | |
parser.add_argument("file", metavar="FILE", nargs=1, help='Path to dict file') | |
parser.add_argument("command", metavar="CMD", nargs=1, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
import contextlib | |
def cmwrap(cm, *cmargs, **cmkwargs): | |
"""Decorator wrapping a context manager around a function call.""" | |
def wrapper(f): | |
@functools.wraps(f) | |
def wrapped_f(*args, **kwargs): | |
with cm(*cmargs, **cmkwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import chain, repeat, islice | |
from collections import deque | |
def sliding_window(iterable, n, fill=False, fillvalue=None): | |
it = iter(iterable) | |
if fill: | |
it = chain(it, repeat(fillvalue, n - 1)) | |
w = deque(islice(it, n - 1)) | |
for x in it: | |
w.append(x) |