Skip to content

Instantly share code, notes, and snippets.

View h1ros's full-sized avatar

Hiros h1ros

View GitHub Profile
@h1ros
h1ros / change_datatype.py
Created February 3, 2020 18:41
save the momery by reducing the data type
def change_datatype(df):
int_cols = list(df.select_dtypes(include=['int']).columns)
for col in int_cols:
if ((np.max(df[col]) <= 127) and(np.min(df[col] >= -128))):
df[col] = df[col].astype(np.int8)
elif ((np.max(df[col]) <= 32767) and(np.min(df[col] >= -32768))):
df[col] = df[col].astype(np.int16)
elif ((np.max(df[col]) <= 2147483647) and(np.min(df[col] >= -2147483648))):
df[col] = df[col].astype(np.int32)
else:
@h1ros
h1ros / 7zcat
Created February 3, 2020 16:46
zcat for 7zip
#!/bin/bash
# copy this file into /bin/zcat to a file called /bin/7zcat
PATH=${GZIP_BINDIR-'/bin'}:$PATH
exec 7z e -so -bd "$@" 2>/dev/null | cat
@h1ros
h1ros / how_to_register_your_ipython_kernel.sh
Created May 5, 2018 23:11
Register ipykernel to your jupyternotebook
python -m ipykernel install --user --name=my-virtualenv-name --display-name "Python 3 (my-virtualenv)"
jupyter notebook
@h1ros
h1ros / remove_duplicate_path.sh
Last active May 5, 2018 22:59
Remove duplicated path in LD_LIBRARY_PATH
if [ -n "$LD_LIBRARY_PATH" ]; then
old_PATH=$LD_LIBRARY_PATH:; LD_LIBRARY_PATH=
while [ -n "$old_PATH" ]; do
x=${old_PATH%%:*} # the first remaining entry
case $LD_LIBRARY_PATH: in
*:"$x":*) ;; # already there
*) LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$x;; # not there yet
esac
old_PATH=${old_PATH#*:}
done
@h1ros
h1ros / peakdet.m
Created January 30, 2018 17:47 — forked from endolith/peakdet.m
Peak detection in Python
function [maxtab, mintab]=peakdet(v, delta, x)
%PEAKDET Detect peaks in a vector
% [MAXTAB, MINTAB] = PEAKDET(V, DELTA) finds the local
% maxima and minima ("peaks") in the vector V.
% MAXTAB and MINTAB consists of two columns. Column 1
% contains indices in V, and column 2 the found values.
%
% With [MAXTAB, MINTAB] = PEAKDET(V, DELTA, X) the indices
% in MAXTAB and MINTAB are replaced with the corresponding
% X-values.