Skip to content

Instantly share code, notes, and snippets.

View jarvisrob's full-sized avatar

Rob Jarvis jarvisrob

  • Melbourne, Australia
View GitHub Profile
@jarvisrob
jarvisrob / pyenv-and-pyenv-virtualenv.sh
Created December 20, 2023 03:33
pyenv and pyenv-virtualenv
# For installation and overview:
# - https://github.com/pyenv/pyenv
# - https://github.com/pyenv/pyenv-virtualenv
# Note all the changes required to dot files
# Example usage *once installed* - using Python 3.10.4 for project in ~/lab/project
# Install Python version
pyenv install 3.10.4
@jarvisrob
jarvisrob / xcode-reinstall.sh
Created March 31, 2023 05:34
Uninstall and reinstall Xcode Command Line Tools for MacOS
# Uninstall
# Check directory for installation is correct, delete folder and all files, check it's been removed
xcode-select -p
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select -p
# Re-install, then check which directory it's been installed into
xcode-select --install
# Confirm and monitor installation through the dialog window that opens
xcode-select -p
@jarvisrob
jarvisrob / upgrade_R_mac_brew.sh
Created March 20, 2020 05:11
Upgrading R on Mac using Homebrew Cask
# Currently using uninstall/install--would be good to see if can use brew cask upgrade, or just install new version side-by-side
brew cask uninstall r
brew cask install r
# Performance without linking BLAS (vecLib) from Apple's Accelerate Framework, i.e. *no* default multi-threading
Rscript -e "sessionInfo()"
Rscript -e "d <- 2e3; system.time({ x <- matrix(rnorm(d^2),d,d); tcrossprod(x) })"
# Link Apple's BLAS to make R run multi-threaded by default where possible and note performance boost
ln -sf \
@jarvisrob
jarvisrob / check_internet.py
Created October 29, 2019 22:18
Python function to check for internet connectivity by attempting to make a socket connection
import socket
def check_internet(host="8.8.8.8", port=53, timeout=3):
# Checks for internet connection by testing to see if it can make a socket connetion to (host, port)
# Host: 8.8.8.8 (google-public-dns-a.google.com)
# Port: 53/tcp
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(timeout)
sock.connect((host, port))
@jarvisrob
jarvisrob / confirm_continue_yN.sh
Created October 29, 2019 22:13
Bash function that pauses script to prompt user to confirm they want to continue [y/N]
confirm_continue_yN() {
# Asks user to confirm to proceed
# $1 is the confirmation message, usually a question
# $2 is the abort message
# Converts user input to lower case before regex check for 'y' or 'yes'
# If it's not one of those responses then exits the script echoing the abort message
read -r -p "$1 [y/N] " response
response_lowercase=$( echo "$response" | awk '{print tolower($0)}' )
if [[ ! "$response_lowercase" =~ ^(yes|y)$ ]]
then