Skip to content

Instantly share code, notes, and snippets.

View josepsmartinez's full-sized avatar

José Pedro Silveira Martinez josepsmartinez

View GitHub Profile
@josepsmartinez
josepsmartinez / install_cuda-10_ubuntu16.sh
Created October 31, 2019 01:42
Install Cuda 10 on Ubuntu 16
#!/bin/bash
# From https://www.tensorflow.org/install/gpu
# Add NVIDIA package repositories
# Add HTTPS support for apt-key
sudo apt-get install gnupg-curl
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_10.0.130-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1604_10.0.130-1_amd64.deb
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
# arguments
$PATH_TO_SUBMODULE=$2
shift
$COMMIT_MESSAGE="$@"
# removal
git submodule deinit $PATH_TO_SUBMODULE
git rm $PATH_TO_SUBMODULE
git commit -m $COMMIT_MSG
rm -rf .git/modules/$PATH_TO_SUBMODULE
@josepsmartinez
josepsmartinez / properties.py
Created December 22, 2020 00:13
Python @Property and @*.setter
# Reference: https://www.programiz.com/python-programming/property
class Dummy():
def __init__(self):
self.msg = "oi" # it calls get and setter functions
@property
def msg(self):
print("Getting...")
return self._msg
@josepsmartinez
josepsmartinez / SCRIPTPATH.sh
Last active March 21, 2022 13:27
Safe practice for attributing a script's directory UNIX path to a shell variable [Reference: https://stackoverflow.com/posts/4774063/revisions (2020/12/27)]
#!/bin/bash
SCRIPTPATH=$( cd $(dirname $0) >/dev/null 2>&1 ; pwd -P )
@josepsmartinez
josepsmartinez / np_arr-b64.py
Last active January 30, 2021 00:52
Numpy array to base64 back and forth (including JSON serialization)
import numpy as np
import base64
import json
def without_serialization(arr):
b64_bytes = base64.b64encode(arr)
bytes_for_np = base64.decodebytes(b64_bytes)
arr_back = np.frombuffer(bytes_for_np, dtype=np.float32)
@josepsmartinez
josepsmartinez / install_pipenv.sh
Created January 31, 2021 08:27
Bash script which installs Python 3 and Pipenv
#!/bin/bash
# Code adapted from: https://stackoverflow.com/a/55423104/4449273
## Tested on Ubuntu 20.04 (running on WSL)
sudo apt install software-properties-common
sudo apt-add-repository universe
sudo apt update
# Python 3
@josepsmartinez
josepsmartinez / trap-int.sh
Created February 8, 2021 14:41
Trapping INT signal on bash script
#!/bin/bash
trap 'echo "Exiting due to keyboard interrupt."; exit' INT
@josepsmartinez
josepsmartinez / install-brave-browser.sh
Created February 14, 2021 06:01
Install Brave Browser
#!/bin/bash
sudo apt install apt-transport-https curl gnupg
curl -s https://brave-browser-apt-release.s3.brave.com/brave-core.asc | sudo apt-key --keyring /etc/apt/trusted.gpg.d/brave-browser-release.gpg add -
echo "deb [arch=amd64] https://brave-browser-apt-release.s3.brave.com/ stable main" | sudo tee /etc/apt/sources.list.d/brave-browser-release.list
sudo apt update
@josepsmartinez
josepsmartinez / arguments-iteration.sh
Created February 16, 2021 17:41
Iterate over arguments in bash
#!/bin/bash
# Reference: https://stackoverflow.com/a/3816747/4449273
for arg in "$@"; do
echo $arg;
done
@josepsmartinez
josepsmartinez / install-jupyter-notebook.sh
Created February 16, 2021 22:20
Install Jupyter Notebook
#!/bin/bash
# Sets up jupyter notebook (as in https://askubuntu.com/a/941745)
ubuntu_20() {
sudo apt install python3-notebook jupyter jupyter-core
}
ubuntu_19() {
sudo apt install python3-notebook jupyter jupyter-core python-ipykernel