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 re | |
SLICE_TEMPLATES = [ | |
('s', r'(?P<i>[+-]?\d+)'), | |
('sp', r'\((?P<i>[+-]?\d+)\)'), | |
('a', r'::?'), | |
('ri-', r'(?P<i>[+-]?\d+)::?'), | |
('ri-k', r'(?P<i>[+-]?\d+)::(?P<k>[+-]?\d+)'), | |
('r-j', r':(?P<j>[+-]?\d+):?'), | |
('r-jk', r':(?P<j>[+-]?\d+):(?P<k>[+-]?\d+)'), |
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
#!/bin/bash | |
# this command list attached volumes; make sure the volume to mount | |
# is in the list | |
lsblk | |
# see if the volume contains file system (skipped if for sure). | |
# the name of the volume is denoted here as `/dev/xvdf', which | |
# should be listed in the output of `lsblk'. | |
# If the output is `/dev/xvdf: data', then it does not have |
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 | |
import argparse | |
import logging | |
import sys | |
def make_parser(): | |
parser = argparse.ArgumentParser( | |
description='Select column(s) of CSV file by name assuming the first ' | |
'row of the CSV lists the column names. Currently the ' |
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
""" | |
Example usage:: | |
.. code-block:: | |
my_npzfile = ... | |
with NpzMMap(my_npzfile) as zfile: | |
with zfile.mmap(data_name) as data: | |
# do anything to memory-mapped ``data`` | |
... |
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 zipfile | |
import io | |
import typing | |
import numpy as np | |
class IncrementalNpzWriter: | |
""" | |
Write data to npz file incrementally rather than compute all and write |
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
""" | |
Defines Moving MNIST dataset and function to generate moving mnist. | |
Adapted from: https://gist.github.com/tencia/afb129122a64bde3bd0c | |
""" | |
import os | |
import math | |
import collections | |
import itertools | |
import bisect |
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 string | |
# Reference: https://stackoverflow.com/a/46161774/7881370 | |
# Access date: 2019-03-23 | |
def count_n_placeholders(template: str) -> int: | |
return sum(1 for _ in filter(lambda x: x[1] is not None, | |
string.Formatter().parse(template))) |
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
def delegates(method_names, to): | |
def dm(method_name): | |
def fwraps(self, *args, **kwargs): | |
wrappedf = getattr(getattr(self, to), method_name) | |
return wrappedf(*args, **kwargs) | |
fwraps.__name__ = method_name | |
return fwraps | |
def cwraps(cls): | |
for name in method_names: | |
setattr(cls, name, dm(name)) |
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
/^ *$/d | |
/^#[^!]/d | |
1,/^#!\(\/bin\/\|\/usr\/bin\/env \)\(ba\)\?sh$/p | |
/^#!\(\/bin\/\|\/usr\/bin\/env \)\(ba\)\?sh$/q |
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
if [ "${BASH_SOURCE[0]}" != "$0" ]; then | |
echo "This script intends to be called rather than be sourced" | |
return 1 | |
fi |