Skip to content

Instantly share code, notes, and snippets.

View mrnabati's full-sized avatar

Ramin Nabati mrnabati

View GitHub Profile
@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 / 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 / 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 / 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"