Skip to content

Instantly share code, notes, and snippets.

View mrnabati's full-sized avatar

Ramin Nabati mrnabati

View GitHub Profile
@mrnabati
mrnabati / ask.sh
Last active August 27, 2019 01:43
Bash Snippets
# This is a general-purpose function to ask Yes/No questions in Bash, either
# with or without a default answer. It keeps repeating the question until it
# gets a valid answer.
ask() {
# https://gist.github.com/davejamesmiller/1965569
local prompt default reply
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
@mrnabati
mrnabati / install_virtualenvwrapper.md
Last active October 6, 2019 16:29
Install and setup virtualenvwrapper in Python3.7
  • Install virtualenv and virtualenvwrapper
    python3.7 -m pip install virtualenv virtualenvwrapper
  • Add the following files to ~/.bashrc or ~/.bash_profile to setup the virtualenv and projects directory. Change the path to python3.7 if in a different path.
    export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3.7
    export WORKON_HOME=$HOME/.virtualenvs

export PROJECT_HOME=$HOME/projects

@mrnabati
mrnabati / save_fig.py
Created September 22, 2019 14:12
Save the current figure in matplotlib in pdf format, removing all whitespaces around the image
def save(filepath, fig=None):
'''
Save the current figure in matplotlib with no whitespace in pdf format
'''
import matplotlib.pyplot as plt
if not fig:
fig = plt.gcf()
plt.subplots_adjust(0,0,1,1,0,0)
for ax in fig.axes:
@mrnabati
mrnabati / gitSolutions.md
Last active May 31, 2024 15:45
Common Git problems (and solutions!)

Working with submodules in your repository

  • Create the submodule:

    git submodule add -b master <git@github.com:MYSUBMODULE.git> <path/to/MYSUBMODULE>

    This creates the submodule and makes it track submodule's master branch. You can change the branch name if you want to track a different branch.

  • Change some settings. In the parent repo:

    # make it so that git status will include changes to submodules.
@mrnabati
mrnabati / .tmux.conf
Last active October 6, 2019 15:46
My tmux configuration (credit: https://github.com/gpakosz/.tmux)
# cat << EOF > /dev/null
# https://github.com/gpakosz/.tmux
# (‑●‑●)> dual licensed under the WTFPL v2 license and the MIT license,
# without any warranty.
# Copyright 2012— Gregory Pakosz (@gpakosz).
# /!\ do not edit this file
# instead, override settings in ~/.tmux.conf.local, see README.md
# -- general -------------------------------------------------------------------
@mrnabati
mrnabati / remote_tensorboard.md
Last active April 11, 2024 11:18
Tensorboard on remote server

Running Tensorboard remotely on a server

Follow these steps to run tensorflow on remote server but see the results on local browser using port forwarding.

  • On the remote machine, run:
    tensorboard --logdir <path> --port 6006
  • On the local machine, run
@mrnabati
mrnabati / install_pip.sh
Created October 13, 2019 20:39
Script to install pip for python3
#!/bin/bash
wget https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py --user
python get-pip.py --user --force
rm get-pip.py
mkdir -p $HOME/.config/pip
ln -s $PWD/conf/pip.conf $HOME/.config/pip/
pip3 install setuptools --upgrade --user
@mrnabati
mrnabati / tmux_error.md
Last active October 14, 2019 18:32
Tmux error: protocol version mismatch

Tmux Protocol Version Mismatch Error

If for some reason you thought it's a good idea to update tmux to a new version without closing your current tmux sessions first, you might see this error when trying to attach to those sessions after update:

  $ tmux attach
  protocol version mismatch (client 7, server 6)

To attach to your sessions, use this awesome hack (credit: this stackexchange answer):

@mrnabati
mrnabati / .gitignore
Last active December 25, 2019 20:31
Python project .gitignore file
### Project Specific ##
### VSCode ###
.vscode/
### MAC OS ###
.DS_Store
.AppleDouble
.LSOverride
@mrnabati
mrnabati / log.py
Created December 26, 2019 07:08
Custom logging module with colors for console
import logging
import time
def getLogger(name, console_level='INFO', file_level=None):
"""
Generate logger with custom formatting. Console and file levels and formatting
if different. Log is saved to a file only if file_level is provided.
"""
## Create a custom logger
logger = logging.getLogger(name)