Skip to content

Instantly share code, notes, and snippets.

View rxa254's full-sized avatar
💭
Clear

Rana X Adhikari rxa254

💭
Clear
View GitHub Profile
@rxa254
rxa254 / livespec.py
Created March 20, 2023 20:26 — forked from boylea/livespec.py
pyqtgraph live running spectrogram from microphone
"""
Tested on Linux with python 3.7
Must have portaudio installed (e.g. dnf install portaudio-devel)
pip install pyqtgraph pyaudio PyQt5
"""
import numpy as np
import pyqtgraph as pg
import pyaudio
from PyQt5 import QtCore, QtGui
@rxa254
rxa254 / cumulativeRMS.md
Created February 4, 2022 06:24
How to plot the cumulative RMS of a power spectral density (or time series)

Sometime you want to know the RMS of only some port of your signal or some part of your power spectral density.

In that case what you may is to start from the highest frequency bin, and add the power in each bin as you go. T his quantity is then the cumulative RMS of the spectrum. At each frequency point, f, the cumulative RMS is the RMS of the signal from the highest frequency to f.

def myrms(f, y_of_f):
    df = np.diff(f)
 df = np.append(df[0],df)
# filter some data using SOS so as to preserve the dynamic range
import numpy as np
import scipy.signal as sig
fs = 1024
bg_raw = np.random.randn(1000)
# This is a bandpass
@rxa254
rxa254 / pdf_compressor.py
Last active April 24, 2023 12:49
How to compress PDF files from the command line
# Author: Sylvain Carlioz
# 6/03/2017
# MIT license -- free to use as you want, cheers.
#
# rxa254@github.com
# modified Jan/2019
# changed input args so it can run on a whole directory
"""
Simple python wrapper script to use ghoscript function to compress PDF files.
@rxa254
rxa254 / ranaplotsettings.py
Last active May 1, 2020 07:14
beautiful - Matplotlib plot settings (my fav)
import matplotlib.pyplot as plt
plt.rcParams.update({'text.usetex': False,
'lines.linewidth': 4,
'font.family': 'serif',
'font.serif': 'Palatino',
'font.size': 22,
'xtick.direction': 'in',
'ytick.direction': 'in',
'xtick.labelsize': 'medium',
@rxa254
rxa254 / .gitignore
Last active April 26, 2020 06:26
gitignore file for python, Matlab, & LaTex & emacs & jupyter & macOS
# Created by https://www.gitignore.io/api/python,matlab,jupyternotebooks,macos,emacs,latex
# Edit at https://www.gitignore.io/?templates=python,matlab,jupyternotebooks,macos,emacs,latex
### Emacs ###
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
@rxa254
rxa254 / time_some_code.rst
Last active April 19, 2020 03:20
How to time parts of your python code

HowTo Time some Piece O' Code =========== I always forget how I should time little parts of my python code when I'm trying to optimize it, so I put it here so that I can just search for it later.

There's a bunch of timing functions in python: Some use various different clocks, but the Stack Exchange wisdom makes me want to use the timeit module.

Here's how its done ----.. codeblock:: python

@rxa254
rxa254 / CleanUpMyRepo.rst
Last active March 14, 2021 23:26
How to clean up large files from your GIT repo

Sometimes people (maybe mistakenly) upload large files to GIT which are not needed. We want our GIT repos to be small and only contain the necessary source files, i.e:

  1. not any large images
  2. not compiled PDF or object files
  3. not large data sets

Those large files which don't need version control can be managed using GIT-LFS.

We can do this using the useful GIT BFG: https://rtyley.github.io/bfg-repo-cleaner/

@rxa254
rxa254 / gist:65e365ecc58d2d9c8887
Created November 30, 2015 05:21 — forked from lucaspiller/gist:3377737
Tmux Primer

I use this function to setup / resume my tmux sessions. If a session exists with the given name it resumes it, otherwise it creates it:

tm() {
  [[ -z "$1" ]] && { echo "usage: tm <session>" >&2; return 1; }
  tmux has -t $1 && tmux attach -d -t $1 || tmux new -s $1
}

(N.b. If you use something similar already check you have the -d flag. This will kill old clients (e.g. ssh connections that died, quitting your terminal before disconnecting) and ensure the window resizes correctly.)