Skip to content

Instantly share code, notes, and snippets.

View iamgroot42's full-sized avatar
🏠

Anshuman Suri iamgroot42

🏠
View GitHub Profile
@iamgroot42
iamgroot42 / test.slurm
Created February 3, 2022 18:13
Example SLURM script for blogpost
#!/bin/bash
#SBATCH --ntasks=1
#SBATCH -A uvasrg
# Total memory requested on system
# Maximum 4 nodes per job allowed
# Maximum 32GB/core allowed
#SBATCH --mem=32G
@iamgroot42
iamgroot42 / gpu_check.sh
Last active June 22, 2023 20:12
Check free memory on all GPUs across multiple servers together (instead of cumbersome sequential login-checks). Custom-made for CS servers @ UVa
#!/bin/bash
read -s password
myfun()
{
f="$(mktemp /tmp/check.XXXXXX)"
nvidia-smi -q -x > $f
python -c "import xml.etree.ElementTree as ET; tree = ET.parse('$f'); root = tree.getroot(); import os; myname = os.uname()[1].split('.')[0]; z = [myname+'['+child.find('minor_number').text+'] : '+child.find('fb_memory_usage').find('free').text+'/'+child.find('fb_memory_usage').find('total').text for child in root.findall('gpu')]; print('\n'.join(z) + '\n')"
}
sshpass -p $password ssh -o StrictHostKeyChecking=no $1@gpusrv01.cs.virginia.edu "$(typeset -f); myfun" &
sshpass -p $password ssh -o StrictHostKeyChecking=no $1@gpusrv02.cs.virginia.edu "$(typeset -f); myfun" &
@iamgroot42
iamgroot42 / rbot.py
Created June 15, 2019 09:56
Random bot : sends random responses. A fun-to-have bot for any group conversation :)
import numpy as np
import random
import getpass
import requests
import time
from telegram import Bot, ParseMode
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
@iamgroot42
iamgroot42 / bookmyshow_stalking.py
Last active April 23, 2019 13:35
Movie (and city/format) specific callback bot for BookMyShow. Update movie/format links in code and run. Ideal usage: add bot to channel, bot will send update messages whenever a cinema is added to the list
from telegram.ext import Updater, CommandHandler
import requests
import time
from bs4 import BeautifulSoup
import logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
cities = ["national-capital-region-ncr", "hyderabad", "bengaluru"]
BOOKING_URL = "https://in.bookmyshow.com/CITY/movies/avengers-endgame/ET00090482"
INFO - 02/22/19 01:59:59 - 0:00:00 - ============ Initialized logger ============
INFO - 02/22/19 01:59:59 - 0:00:00 - adversarial: True
batch_size: 32
cuda: True
dico_build: S2T
dico_eval: default
dico_max_rank: 0
dico_max_size: 0
dico_method: csls_knn_10
dico_min_size: 0
@iamgroot42
iamgroot42 / setup.sh
Created March 11, 2018 15:03
Installation of ns3, protobuf and zeromq on Ubuntu 16
#!/bin/bash
# Install pre-requisites
sudo apt-get -y install gcc g++ python
sudo apt-get -y install mercurial python-setuptools git
sudo apt-get -y install qt5-default
sudo apt-get -y install python-pygraphviz python-kiwi python-pygoocanvas libgoocanvas-dev ipython
sudo apt-get -y install openmpi-bin openmpi-common openmpi-doc libopenmpi-dev
sudo apt-get -y install autoconf cvs bzr unrar
sudo apt-get -y install gdb valgrind
@iamgroot42
iamgroot42 / dyamic_memory_growth.py
Created January 28, 2018 12:38
Dynamic memory allocation
import tensorflow as tf
import keras
# Don't hog GPU
config = tf.ConfigProto()
config.gpu_options.allow_growth=True
sess = tf.Session(config=config)
# If using Keras, add this line:
keras.backend.set_session(sess)
@iamgroot42
iamgroot42 / logger.sh
Last active February 12, 2017 08:42
A simple script to keep track of which user has used a GPU for how much time (for a single GPU machine)
#!/bin/bash
pids=$(nvidia-smi | awk '$2=="Processes:" {p=1} p && $3 > 0 {print $3}' | grep -o '[0-9]*')
if [ ${#pids[@]} -gt 0 ]
then
date >> GPU_LOGFILE
fi
for p in $pids
@iamgroot42
iamgroot42 / login.py
Created January 7, 2017 10:40
A simple Python script to log into IIITD's firewall
import urllib
import urllib2
import time
time.sleep(1)
link = "http://www.gogole.com/"
req = urllib2.Request(link)
response = urllib2.urlopen(req)
a = response.read()
@iamgroot42
iamgroot42 / ocv14.sh
Last active October 18, 2018 22:59
Download and install openCV 3.0 on Ubuntu 14.04 for Python 2 (no virtualenv) Raw
#!/bin/bash
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get install -y build-essential cmake git pkg-config
sudo apt-get install -y libjpeg8-dev libtiff4-dev libjasper-dev libpng12-dev
sudo apt-get install -y libgtk2.0-dev
sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev libv4l-dev