Skip to content

Instantly share code, notes, and snippets.

View kakodkar's full-sized avatar

Mayank Kakodkar kakodkar

View GitHub Profile
#%%
import time
import os
import seaborn as sns
import matplotlib
import __main__
try:
get_ipython
except:
# Use Agg when not in notebook
@kakodkar
kakodkar / gist:5fb03fa97f71273b593b13dfc27cf842
Created May 25, 2021 22:18
Stub for adding appropriate import path for VSCODE development
REPL = not hasattr(__main__, '__file__')
import sys
if REPL:
sys.path.append('src/')
@kakodkar
kakodkar / make_counters_mul_div_compliant.py
Created June 2, 2019 14:53
Add multiply and divide with scalar capability to collections.Counter class in python
Counter.__mul__ = lambda self, other: Counter({k: v * other for k, v in self.items()})
Counter.__truediv__ = lambda self, other: Counter({k: v / other for k, v in self.items()})
@kakodkar
kakodkar / conda_installation.sh
Created April 15, 2019 20:13
Installing Numba and Anaconda on Linux Servers
# If you don't have an installation of conda install using
# https://docs.anaconda.com/anaconda/install/linux/
wget -c https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh
chmod +x Anaconda3-2019.03-Linux-x86_64.sh
./Anaconda3-2019.03-Linux-x86_64.sh
# If you have one, update library defs using
conda update conda
# Create an environment 'py3' with python 3.7 and basic packages as
@kakodkar
kakodkar / Byobu
Created February 26, 2019 17:39
Byobu configuration, helpful links
byobu keybindings can be user defined in /usr/share/byobu/keybindings/
(or within .screenrc if byobu-export was used). The common key bindings are:
F2 - Create a new window
F3 - Move to previous window
F4 - Move to next window
F5 - Reload profile
F6 - Detach from this session
F7 - Enter copy/scrollback mode
F8 - Re-title a window
@kakodkar
kakodkar / python_multithreading_hack.py
Created February 14, 2019 20:16
A hack to run class functions in a multithreaded manner
import itertools
import time
from multiprocessing.pool import Pool
class Test:
@classmethod
def x(cls,y):
time.sleep(y)
print(f"{y}")
@kakodkar
kakodkar / fast_auc.py
Last active June 2, 2019 14:53
Super Fast AUC computation (Personally I have switched back to the scikit learn function for simplicity and am using au_prc instead)
@classmethod
def get_tpr_fpr(cls, pre_sigmoid_input, target):
pre_sigmoid_input = pre_sigmoid_input.data.cpu().numpy()
target = target.data.cpu().numpy()
tpr = np.zeros_like(pre_sigmoid_input)
fpr = np.zeros_like(pre_sigmoid_input)
cls._tpr_fpr(tpr, fpr, pre_sigmoid_input, target)
fpr = np.sort(fpr)
tpr = np.sort(tpr)
auc = np.sum((fpr[1:] - fpr[:-1]) * tpr[1:])
@kakodkar
kakodkar / nvidia_smi.py
Created January 28, 2019 19:24
Script to replace nvidia-smi
from pynvml import *
nvmlInit()
for i in range(4):
try:
handle = nvmlDeviceGetHandleByIndex(i)
info = nvmlDeviceGetMemoryInfo(handle)
print "Device:\t", i , "Used memory:\t", float(info.used)/1024/1024/1024, "Total memory:\t", float(info.total)/1024/1024/1024
except:
pass
nvmlShutdown()
@kakodkar
kakodkar / find_pdf_with_type_3_fonts.sh
Created January 28, 2019 19:23
Find pdf with type 3 fonts
# Needs poppler, for mac use:
# brew install poppler
for i in `grep -nair 'includegraphics' ./* | grep pdf | grep -v '%' | perl -ne '/\{(.*?)\}/; print"$1\n"'` 1 ↵ ✹ ✭master
do
echo $i; pdffonts $i
done
@kakodkar
kakodkar / create_a_smaller_dataset_from_huge_csv.sh
Created January 28, 2019 19:21
Create a smaller dataset from huge csv
#!/bin/bash
cat donations.csv.bkp | grep -v donationid | gshuf | head -n 1000 > donations.csv.tmp && head -n1 donations.csv.bkp > donations.csv && cat donations.csv.tmp >>donations.csv