This file contains hidden or 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
# -*- coding: utf-8 -*- | |
import os | |
import sys | |
import glob | |
try: | |
import ujson as json | |
except ImportError: | |
import ujson as json | |
import argparse |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
import os | |
import sys | |
import glob | |
import numpy as np | |
try: | |
import ujson as json | |
except ImportError: | |
import json |
This file contains hidden or 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 os | |
os.path.dirname(os.path.realpath(__file__)) |
This file contains hidden or 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
WHERE XX defines the priority. -19 being highest priority. 19 being the lowest. | |
sudo renice -n [XX] [PID] | |
nice -n [XX] [COMMAND] |
This file contains hidden or 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 numpy as np | |
from numpy.lib.stride_tricks import as_strided | |
def rolling_block(A, block=(3, 3)): | |
shape = (A.shape[0] - block[0] + 1, A.shape[1] - block[1] + 1) + block | |
strides = (A.strides[0], A.strides[1]) + A.strides | |
return as_strided(A, shape=shape, strides=strides) | |
X = np.random.randint(0, 200, (10, 10)) |
This file contains hidden or 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
""" | |
Specifically, the Kullback–Leibler divergence from Q to P, denoted DKL(P‖Q), is | |
a measure of the information gained when one revises one's beliefs from the | |
prior probability distribution Q to the posterior probability distribution P. In | |
other words, it is the amount of information lost when Q is used to approximate | |
P. | |
""" | |
import numpy as np | |
from scipy.stats import entropy |
This file contains hidden or 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 os | |
import click | |
def read_file(filename): | |
with open(filename) as in_file: | |
for line in in_file: | |
if line.strip() != '': | |
yield line.strip() |
This file contains hidden or 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
files = [path/to/file, path/to/file2, path/to/file3] | |
with zipfile.ZipFile('/tmp/test.zip', 'w', zipfile.ZIP_DEFLATED) as out_file: | |
for rel_filename in files: | |
absname = os.path.abspath(rel_filename) | |
root = os.path.dirname(absname) | |
filename = os.path.relpath(rel_filename, root) | |
out_file.write(rel_filename, filename) | |
print(absname, root, filename) |
This file contains hidden or 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
# Ask for the user password | |
# Script only works if sudo caches the password for a few minutes | |
sudo true | |
# Install kernel extra's to enable docker aufs support | |
# sudo apt-get -y install linux-image-extra-$(uname -r) | |
# Add Docker PPA and install latest version | |
# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9 | |
# sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list" |
This file contains hidden or 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
""" | |
Simple utility command line tool to list the sheet names of an Excel workbook. | |
""" | |
import argparse | |
from xlrd import open_workbook | |
def get_args(): | |
"""This function parses and return command line arguments""" | |
parser = argparse.ArgumentParser(description='List sheetnames in Excel workbook.') |