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
""" | |
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 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
""" | |
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
#!/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
#!/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
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
#!/usr/bin/env python3 | |
import os | |
import sys | |
import argparse | |
import subprocess | |
import ast | |
HOMEDIR = os.path.normpath(os.environ['HOME']) | |
MUSICDIR = os.path.join(HOMEDIR, 'Music') | |
COVERARTDIR = os.path.join(MUSICDIR, '.cover-arts') |
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
# original command adapted from https://superuser.com/a/100290 | |
import subprocess | |
filename = ... | |
try: | |
_ = subprocess.check_call(['ffmpeg', '-v', 'error', '-i', | |
filename, '-f', 'null', '-']) | |
except subprocess.CalledProcessError: | |
# the subprocess call returns non-zero, which means filename |
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
#include "rbtree.h" | |
rbnode *left_rotate(rbnode *x) | |
{ | |
// assert(x && x->right); | |
rbnode *y = x->right; | |
x->right = y->left; | |
y->left = x; | |
return y; | |
} |