Skip to content

Instantly share code, notes, and snippets.

@estysdesu
estysdesu / loadPaths.sh
Last active July 21, 2019 04:45
[Bash: profile load paths] #bash #profile #source #sh
# list profile paths loading variables
sudo bash -c "echo exit|dtruss bash -li|& less|grep '^open'"
# .bash_profile is for login shell, whereas .bashrc is for non-login shell (SSH)
@estysdesu
estysdesu / chsh.sh
Last active July 21, 2019 04:53
[Shell: add a new shell and change default] #chsh #sh
# add a new default shell
sudo vim /etc/shells
chsh -s <path to shell>
@estysdesu
estysdesu / sig_x_corr.py
Last active July 21, 2019 05:02
[Python: signal cross correlation (signal/phase comparison)] #cross #correlation #signals #numpy #xcorr #np
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]
@estysdesu
estysdesu / grad_n.py
Last active July 21, 2019 05:02
[Python: Numpy n-th gradient (recursion)] #numpy #gradient #slope #recursion #np
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
@estysdesu
estysdesu / ma.py
Last active July 21, 2019 05:02
[Python: Numpy mask arrays] #numpy #maskarray #python #ma #np
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]
@estysdesu
estysdesu / drop_tracker.py
Last active July 21, 2019 05:03
[Python: track values that are removed from an origin array] #maskedarray #numpy #np #ma
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)
@estysdesu
estysdesu / ppPath.sh
Created July 21, 2019 05:11
[Shell: pretty pring PATH] #sh #path #pprint #pretty #print
#!/usr/bin/env bash
# https://github.com/estysdesu/dotFiles/blob/master/bash/.bash_profile
alias ppPATH="echo $PATH | tr -s ':' '\n'" # each path member gets it's own line
@estysdesu
estysdesu / update_size.js
Last active July 21, 2019 05:51
[JavaScript: resize all elements of a HTML tag] This sets height = width #resize #js #html #dom
function updateSize() {
var projectTile = document.querySelectorAll("#projects .tile.is-child");
projectTile.forEach( function(tile, index) {
if (window.innerWidth > 768) {
tile.style.height = getComputedStyle(tile).width;
} else {
tile.style.height = null;
}
})
}
@estysdesu
estysdesu / med_filt.py
Last active July 21, 2019 05:51
[Python: median filter (1d)] #median #filter #medfilt #window #python
#!/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)
@estysdesu
estysdesu / window.py
Last active July 21, 2019 05:51
[Python: windows of an iterable with repeating edge case condition] #window #python
#!/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")