Skip to content

Instantly share code, notes, and snippets.

View hantoine's full-sized avatar

Antoine Hebert hantoine

View GitHub Profile
@hantoine
hantoine / download_and_unzip.py
Last active October 27, 2024 04:10
Download and extract a ZIP file in Python
from urllib.request import urlopen
from io import BytesIO
from zipfile import ZipFile
def download_and_unzip(url, extract_to='.'):
http_response = urlopen(url)
zipfile = ZipFile(BytesIO(http_response.read()))
zipfile.extractall(path=extract_to)
@hantoine
hantoine / tensorboard_in_kaggle_notebook.py
Last active May 13, 2024 17:11
Launch TensorBoard in a Kaggle notebook and create a tunnel with ngrok to access it
from urllib.request import urlopen
from io import BytesIO
from zipfile import ZipFile
from subprocess import Popen
from os import chmod
from os.path import isfile
import json
import time
import psutil
@hantoine
hantoine / conda-auto-env.sh
Created December 7, 2020 03:24
Automatically activate a conda environment when entering a directory
# The following lines should be added to the file ~/.bashrc
# When the current working directory contains a file named .conda-auto-env, the
# conda environement whose name is the content of the file will be activated
conda-auto-env() {
if [ -e ".conda-auto-env" ] ; then
env=$(cat .conda-auto-env)
if [ "$CONDA_DEFAULT_ENV" != "$env" ] ; then
conda activate $env
fi
fi

Create a new encrypted partition

  1. Create the partition using GParted for example and take note of the partition path (/dev/sd*).
  2. Use the command sudo cryptsetup luksFormat <device path> to create the encrypted partition.

Create an LVM physical volume in the encrypted partition

  1. Using GParted, for example, "Open" the encrypted partition.
  2. Using the command lsblk, you should see the encrypted partition with a name ending with _crypt, take note of it.
  3. Create the LVM Physical volume using the command sudo pvcreate /dev/mapper/<encrypted partition name>.
@hantoine
hantoine / .gitconfig
Last active August 8, 2024 09:39
My git config
[user]
email =
name = Antoine Hebert
[alias]
cam = commit -am
s = status
ci = commit
pu = push
llg = log --graph --all --decorate
lg = log --graph --abbrev-commit --decorate --format=format:'%C(cyan)%h%C(reset) - %C(green)(%ar)%C(reset) %C()%s%C(reset) %C(cyan)- %an%C(reset)%C(yellow)%d%C(reset)' --all
#!/bin/bash
for br in $(git br | cut -c 3-) ; do
if [ "$br" == "master" ] ; then
continue
fi
git co "$br"
state=$(gh pr status --json state --jq .currentBranch.state)
if [ "$state" == "MERGED" ] ; then
git co master
@hantoine
hantoine / install_xelatex_on_mac.txt
Last active February 10, 2022 21:33 — forked from peterhurford/install_xelatex_on_mac.txt
How to install latex and xelatex on Mac so that Jupyter "Download as PDF" will work
brew install pandoc
brew tap homebrew/cask
brew --cask install basictex
eval "$(/usr/libexec/path_helper)"
export PATH="$PATH:/Library/TeX/texbin/"
sudo tlmgr update --self
sudo tlmgr install texliveonfly
sudo tlmgr install adjustbox
sudo tlmgr install tcolorbox
sudo tlmgr install collectbox
@hantoine
hantoine / argo-in-kind.md
Last active July 11, 2022 13:44 — forked from darpr/argo-in-kind.md
"Argo Workflow" in `kind` Cluster

Argo in Kind

Play with "Argo Workflow" in your local kind cluster.

Prerequisites

The following instructions were tested in macOS Monterey (12.4), on 10 Jul 2022.

Docker Runtime

Ensure docker is installed and running.

K8s Client

@hantoine
hantoine / github_aliases.sh
Created March 3, 2023 17:14
Github CLI Aliases
alias ghopen='gh pr view -w '
alias ghcreate="git publish && gh pr create --body-file ${MLPV2_DIR}/.github/pull_request_template.md --fill --draft && sleep 1 && ghopen"
alias ghstate="gh pr status --json state | jq -r '.currentBranch.state'"
@hantoine
hantoine / graceful_httpserver.go
Last active May 4, 2023 18:21 — forked from ivan3bx/graceful_httpserver.go
Example of handling graceful shutdowns with gin-gonic
// runServer will start the HTTPServer, handling graceful
// shutdown on receives SIGTERM / SIGINT.
func runServer(addr string, engine *gin.Engine) {
s := &http.Server{
Addr: addr,
Handler: engine.Handler(),
}
go func() {
log.Info("server starting")