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 / 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 / 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 / ssh_jupyter.sh
Last active December 27, 2022 13:29
How to start jupyter notebook over server and doing ssh
# Refer https://fizzylogic.nl/2017/11/06/edit-jupyter-notebooks-over-ssh/
# On server
jupyter notebook --no-browser --port=8080
# On local machine
ssh -N -L 8080:localhost:8080 <remote_user>@<remote_host>
@shubhamagarwal92
shubhamagarwal92 / download_drive_file.sh
Created April 9, 2019 22:52
Get file from google drive using terminal
# https://stackoverflow.com/a/52076633/3776827
# Run as download_drive_file.sh file_id
# where file_id is google drive file id
# https://drive.google.com/file/d/0B-u9nH58139bTy1XRFdqaVEzUGs/view
# Eg. file_id here is 0B-u9nH58139bTy1XRFdqaVEzUGs
curl gdrive.sh | bash -s $1
@julia-git
julia-git / gist:feb6253187b05aa9071c1c0721488f60
Last active December 17, 2019 05:10
generate_wordcloud
from wordcloud import WordCloud, STOPWORDS
from PIL import Image
import urllib
import requests
import numpy as np
import matplotlib.pyplot as plt
words = 'access guest guest apartment area area bathroom bed bed bed bed bed bedroom block coffee coffee coffee coffee entrance entry francisco free garden guest home house kettle kettle kitchen kitchen kitchen kitchen kitchen kitchenliving located microwave neighborhood new park parking place privacy private queen room san separate seperate shared space space space street suite time welcome'
mask = np.array(Image.open(requests.get('http://www.clker.com/cliparts/O/i/x/Y/q/P/yellow-house-hi.png', stream=True).raw))
@peteflorence
peteflorence / pytorch_bilinear_interpolation.md
Last active June 30, 2024 01:26
Bilinear interpolation in PyTorch, and benchmarking vs. numpy

Here's a simple implementation of bilinear interpolation on tensors using PyTorch.

I wrote this up since I ended up learning a lot about options for interpolation in both the numpy and PyTorch ecosystems. More generally than just interpolation, too, it's also a nice case study in how PyTorch magically can put very numpy-like code on the GPU (and by the way, do autodiff for you too).

For interpolation in PyTorch, this open issue calls for more interpolation features. There is now a nn.functional.grid_sample() feature but at least at first this didn't look like what I needed (but we'll come back to this later).

In particular I wanted to take an image, W x H x C, and sample it many times at different random locations. Note also that this is different than upsampling which exhaustively samples and also doesn't give us fle

@santisbon
santisbon / Search my gists.md
Last active November 1, 2024 16:22
How to search gists.

Enter this in the search box along with your search terms:

Get all gists from the user santisbon.
user:santisbon

Find all gists with a .yml extension.
extension:yml

Find all gists with HTML files.
language:html

@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active November 15, 2024 09:51
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname