diff --git a/util.py b/util.py index 5fe99ee..8ee8359 100644 --- a/util.py +++ b/util.py @@ -18,6 +18,7 @@ def pairwise(iterable): next(b, None) return izip(a, b) + def batched(iterable, batch_size): """ """ @@ -34,6 +35,13 @@ def batched(iterable, batch_size): if len(pending) > 0: yield batch + +def pad(iterable, padding=None, size=None): + if size is None: + return itertools.chain(iterable, itertools.repeat(padding)) + return itertools.islice(pad(iterable, padding), size) + + def contains_duplicates(sorted_iterable): """Determine in an iterable series contains duplicates. @@ -130,4 +138,9 @@ def filename_from_handle(fh): def now_millis(): millis = int(round(time.time() * 1000)) - return millis \ No newline at end of file + return millis + + +def round_up(integer, multiple): + """Round up to the nearest multiple""" + return integer if integer % multiple == 0 else integer + multiple - integer % multiple \ No newline at end of file