Skip to content

Instantly share code, notes, and snippets.

View shubhamagarwal92's full-sized avatar
☃️
Focusing

Shubham Agarwal shubhamagarwal92

☃️
Focusing
View GitHub Profile
@shubhamagarwal92
shubhamagarwal92 / pandas.py
Last active September 14, 2021 14:01
Pandas helper functions for analysis
import pandas as pd
def read_json_to_df(file_path):
# df = pd.read_json(path_or_buf=file_path,orient='records',lines=True)
df = pd.read_json(path_or_buf=file_path, orient='records')
return df
def read_json_list_to_df(json_list):
df = pd.DataFrame.from_records(json_list)
@shubhamagarwal92
shubhamagarwal92 / counter_dictionary.py
Last active March 3, 2020 14:55
maintain a counter of items using dic
from collections import defaultdict
# method 1
my_dict = defaultdict(int)
my_dict[key] += 1
# method 2
my_dict = {}
my_dict[key] = my_dict.get(key, 0) + 1
@shubhamagarwal92
shubhamagarwal92 / wget.sh
Created September 30, 2019 15:27
different wget flags
# Provide the path where to download
wget https://www.dropbox.com/s/twmtutniktom7tu/VisualDialog_val2018.zip?dl=0 -P ./data
# Provide the name of the file
wget https://www.dropbox.com/s/twmtutniktom7tu/VisualDialog_val2018.zip?dl=0 -O VisualDialog_val2018.zip
@shubhamagarwal92
shubhamagarwal92 / recursive_copy_except_ext_files.sh
Created September 20, 2019 19:34
To copy all files recursively in a folder except .ext files
# To copy all files recursively in a folder except .pth files
# Be careful no "/" in source_dir whle "/" in final_dir
rsync -avr --exclude=*.pth source_dir final_dir/
# For a file in just one folder
cp -r !(*.png) dest
@shubhamagarwal92
shubhamagarwal92 / rm_in_range.sh
Created September 14, 2019 17:45
delete files in a particular range
rm checkpoint_{6..8}.pth
@shubhamagarwal92
shubhamagarwal92 / monitor.sh
Last active December 9, 2022 10:00
Helps in monitoring your code runs
tail -f logs.txt
watch -n1 nvidia-smi
htop
watch -n 1 free -h
@shubhamagarwal92
shubhamagarwal92 / tmux_cheatsheet
Created August 20, 2019 17:58
Cheatsheet for tmux
slit horizontal ctrl+b "
unsplit horizontal ctrl+b x
@shubhamagarwal92
shubhamagarwal92 / print_argparse.py
Created August 12, 2019 17:29
Prints command line arguments from argparse
import argparse
args = parser.parse_args()
for arg in vars(args):
print("{:<20}: {}".format(arg, getattr(args, arg)))
@shubhamagarwal92
shubhamagarwal92 / Dockerfile
Last active August 9, 2019 23:30
This shows how to create an environment and sourcing it in dockerfile
RUN /bin/bash -c "apt-get install tmux -y"
RUN /bin/bash -c "apt-get install htop -y"
# Trying conda environment
RUN /opt/conda/bin/conda create -y --name myenv python=3.6.8 && \
/opt/conda/bin/conda clean -ya
RUN echo "source activate myenv" > ~/.bashrc
ENV PATH /opt/conda/envs/myenv/bin:$PATH
@shubhamagarwal92
shubhamagarwal92 / time_cody.py
Created August 7, 2019 09:46
Time your code to see the execution time
import time
start = time.time()
"the code you want to test stays here"
end = time.time()
print(end - start)