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
#!/usr/bin/env python3 | |
# https://github.com/keystroke3/redpaper/issues/1#event-2480042391 | |
def empty_string_checker(s): | |
if not s: # this is equivalent to saying `if s == "":` | |
print("String is empty!") | |
if s: # this is equivalent to saying `if s != "":` | |
print("String is not empty -- it contains '{}'".format(s)) | |
g = "" |
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
#!/usr/bin/env python3 | |
import window # https://gist.github.com/estysdesu/af7301fa17817c0d0ac7b5f8952c9bfe | |
def median_filt_1d(data, w_size): | |
""" Median filter for 1d data. Edges are handled with a window shift. """ | |
windowed_data = window(data, w_size) | |
w_half_size = w_size//2 | |
for i, w_data in enumerate(windowed_data): | |
w_data_sort = sorted(w_data) |
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 | |
def grad_n(y, x, n, edge_order=2): | |
g = np.gradient(y, x, edge_order=edge_order) | |
for _ in range(n-1): | |
g = grad_n(g, x, 1, edge_order=edge_order) | |
return g |
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
# PyInstaller/bindepend.py | |
#----------------------------------------------------------------------------- | |
# Copyright (c) 2013-2018, PyInstaller Development Team. | |
# | |
# Distributed under the terms of the GNU General Public License with exception | |
# for distributing bootloader. | |
# | |
# The full license is in the file COPYING.txt, distributed with this software. | |
#----------------------------------------------------------------------------- |
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 | |
def drop_tracker(curArr, rmIndxs, dropTracker): | |
""" | |
Track values that are removed from an array. | |
dropTracker is a MaskedArray that curArr has derived from and slightly changed. | |
Requires curArr pts to be closer to their complimentary dropTracker pts more than any other dropTracker pts. | |
""" | |
assert type(dropTracker) is np.ma.MaskedArray | |
newArr = np.delete(curArr, rmIndxs) |
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 | |
x1 = np.ma.array([0, 1, 2, 3, 4]) | |
x1.mask # --> [False] | |
x2 = np.ma.array([0, 1, 2, 3, 4], mask=[False]) # triggers mask expansion | |
x2.mask # --> [False, False, False, False, False] |
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 | |
t = np.linspace(0, 4*np.pi, 100) | |
y1 = np.sin(t) | |
randomizer = lambda x: x + np.random.choice([-1, 1])*np.random.rand() | |
# y2 = np.apply_along_axis(randomizer, 0, y1) # applies once on whole array instead of per element of array | |
vRandomizer = np.vectorize(randomizer) | |
y2 = vRandomizer(y1) | |
corr = np.corrcoef(y1, y2)[0, 1] # choose a value from the left --> right diagonal; either [0, 1] or [1, 0] |
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
#!/usr/bin/env python3 | |
def window(data, w_size): | |
""" Get all windows for a list with an odd window size. """ | |
if not getattr(data, '__iter__', False): | |
raise ValueError("data must be an iterable") | |
if w_size%2 != 1: | |
raise ValueError("window size must be odd") | |
if w_size > len(data): | |
raise ValueError("window size must be less than the data size") |
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
#!/usr/bin/env python3 | |
import shutil, subprocess | |
cmd = shutil.which("python3") | |
try: | |
runner = subprocess.run(cmd, check=True) | |
except subprocess.CalledProcessError as e: # python3 is not found in path | |
print(str(e)) | |
exit(1) |
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
##### Ubuntu/Debian Apt ##### | |
# /etc/apt/apt.conf.d/proxy.conf | |
# https://www.serverlab.ca/tutorials/linux/administration-linux/how-to-set-the-proxy-for-apt-for-ubuntu-18-04/ | |
Acquire { | |
HTTP::proxy "<ip-addr>"; | |
HTTPS::proxy "<ip-addr>"; | |
} |