Skip to content

Instantly share code, notes, and snippets.

View wiccy46's full-sized avatar

Jiajun wiccy46

  • Holoplot
  • Berlin
View GitHub Profile
@wiccy46
wiccy46 / os_tips.py
Last active May 10, 2020 08:57
[os_tips] os tips #python
# Find python path
import os
import sys
os.path.dirname(sys.executable)
# Abs path of project:
os.path.dirname(os.path.abspath(__file__))
@wiccy46
wiccy46 / conda_create.md
Last active February 17, 2020 08:25
[conda_create]Create conda env and delete #conda #python

conda create -n yourenvname python=x.x anaconda

conda remove --name myenv --all

@wiccy46
wiccy46 / jupyter_extensions.md
Created July 8, 2019 07:59
[jupyter_extensions]Install jupyter notebook extension #python #jupyter

Terminal: conda install -c conda-forge jupyter_contrib_nbextensions conda install -c conda-forge jupyter_nbextensions_configuratorj

@wiccy46
wiccy46 / dbamp.py
Created July 8, 2019 08:00
[dbamp]Convert dB to amplitude #python
for i in value_in_dB:
print pow (10, float(i)/20)
@wiccy46
wiccy46 / timeit.py
Last active April 28, 2020 05:41
[timer_decorator]Timeit decorator or class decorator#python
import time
def timeit(method):
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
if 'log_time' in kw:
name = kw.get('log_name', method.__name__.upper())
kw['log_time'][name] = int((te - ts) * 1000)
@wiccy46
wiccy46 / load_all_csv.py
Created July 8, 2019 10:22
[load_all_csv]Load all CSV files only in a folder. #python #pandas
def get_all_data(fp):
l = os.listdir(fp)
try: l.remove(".DS_Store")
except: pass
for i, fname in enumerate(l):
temp_df = pd.read_csv(fp + fname)
if (i == 0):
r = temp_df
else:
r = r.append(temp_df)
@wiccy46
wiccy46 / label_slider.py
Created July 8, 2019 10:26
[label_slider]Pyqt5 Label slider. This create text ticks alongside qt slider #python #qt
from PyQt5.QtGui import QPainter, QPen, QFont
from PyQt5.QtWidgets import QAbstractButton, QSlider, QWidget, QVBoxLayout, QHBoxLayout,\
QStyleOptionSlider, QStyle
from PyQt5.QtCore import Qt, QRect, QPoint
import numpy as np
class LabeledSlider(QWidget):
def __init__(self, minimum, maximum, interval=1, orientation=Qt.Horizontal,
labels=None, p0=0, parent=None):
@wiccy46
wiccy46 / ps.md
Created July 13, 2019 08:49
[Powershell]Useful Powershell Tips #Powershell

To rename a tab where you are : $psise.CurrentPowerShellTab.DisplayName = 'Dev'

To rename a remote tab, you need to do that from a local one (where the first tab is [0] ): $psise.PowerShellTabs[1].DisplayName = 'Remote-Server01'

@wiccy46
wiccy46 / mse.py
Created July 17, 2019 13:56
[MSE]Mean square error #python
def mse(imageA, imageB):
# the 'Mean Squared Error' between the two images is the
# sum of the squared difference between the two images;
# NOTE: the two images must have the same dimension
err = np.sum((imageA - imageB) ** 2)
err /= float(imageA.shape[0] * imageA.shape[1])
# return the MSE, the lower the error, the more "similar"
# the two images are
return err
@wiccy46
wiccy46 / env_detect.py
Last active July 23, 2019 08:25
[env_detec]Envelope Detections of signal #python #dsp
"""1: Peak Detection"""
def envfol_peak_detection(sig, sr, chunk=4, order=6, lpfreq=150):
"""Envelope follower based on peak detection"""
s = sig.shape[0] // chunk
new_sig = np.array_split(np.abs(sig), s)
result = []
for i in new_sig:
result.append(np.max(i))
result = np.array(result)