Skip to content

Instantly share code, notes, and snippets.

View nkthiebaut's full-sized avatar

Nicolas nkthiebaut

View GitHub Profile
@nkthiebaut
nkthiebaut / .gitconfig
Last active February 9, 2024 05:14
Basic git config and aliases
[alias]
st = status
di = diff
co = checkout
ci = commit
br = branch
sta = stash
llog = log --date=local
flog = log --pretty=fuller --decorate
lg = log --graph --abbrev-commit --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
@nkthiebaut
nkthiebaut / bash_terminal
Last active March 20, 2023 22:40
Basic bash terminal set up script
git config --global credential.helper store
git config --global user.email bobby@gmail.com
git config --global user.name bobby
export PS1="\[\033[38;5;133m\]\t\[$(tput sgr0)\] \[$(tput sgr0)\]\[\033[38;5;33m\]\w\[$(tput sgr0)\] \[$(tput sgr0)\]\[\033[38;5;2m\]\\$\[$(tput sgr0)\] \[$(tput sgr0)\]"
alias ls='ls --color=auto'
@nkthiebaut
nkthiebaut / sagemaker_notebook_github_sso
Last active September 29, 2022 20:31
Script to add a GitHub repo on a SageMaker notebook when SSO is enforce on GitHub
# 0: Attach a lifecycle configuration to you Notebook instance to persist environments between sessions
# See https://modelpredict.com/sagemaker-save-your-conda-environments/ for instruction
# Alternative: create environments under the persisted folder (/home/ec2-user/SageMaker) with
# conda create -p /home/ec2-user/SageMaker/py310 python=3.10
# then systematically symlink: ln -s /home/ec2-user/SageMaker/py310 ~/anaconda3/envs/py310
# 1: Create a new conda environment and make it accessible to SageMaker
conda create -y -n py310 python=3.10
conda activate py310
# From https://forum.deepchem.io/t/deploying-a-deepchem-sagemaker-notebook-instance/174
@nkthiebaut
nkthiebaut / jupyterlab_colab.sh
Created August 4, 2021 04:36
Jupyter Lab on Google Colab
pip install -q jupyterlab
ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa <<<y >/dev/null 2>&1
eval "$(ssh-agent -s)"
ssh-add
jupyter lab --ip=0.0.0.0 --port=8989 --allow-root & ssh -o StrictHostKeyChecking=no -R 80:localhost:8989 ssh.localhost.run
@nkthiebaut
nkthiebaut / move_unpack_sagemaker_models.py
Created July 27, 2021 04:29
Move and unpack sagemaker models
import tarfile
import subprocess
import os
import s3fs
REQUIRED_AWS_ENV = {"AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_DEFAULT_REGION"}
def setup_aws_fs() -> s3fs.S3FileSystem:
"""Check the presence of AWS required environment variables
and return an S3 filesystem object.
#!/usr/bin/env bash
# From https://betterdev.blog/minimal-safe-bash-script-template/
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
@nkthiebaut
nkthiebaut / add_definition.gs
Created December 1, 2020 19:10
Fetch the definition of a word when added to a Google Spreadsheet
function onNewRow(e) {
var sheet = SpreadsheetApp.getActiveSheet();
Logger.log("Trigger: new row inserted:" + sheet.getLastRow());
// Get index of row inserted
var row = sheet.getLastRow();
// Get word/phrase inserted
var range = sheet.getRange(row, 1);
var phrase = range.getValue();
Logger.log("Row insertion detected");
@nkthiebaut
nkthiebaut / plot_roc_curve.py
Last active November 20, 2020 12:37
Plot a good-looking roc curve with thresholds
from sklearn.metrics import roc_curve, auc
def plot_roc_curve(true_labels, scores):
""" Plot ROC curve with associated score thresholds """
# compute fpr, tpr, thresholds and roc_auc
fpr, tpr, thresholds = roc_curve(true_labels, scores)
roc_auc = auc(fpr, tpr) # compute area under the curve
fig, ax = plt.subplots()
# Official doc: https://docs.python.org/3/howto/logging-cookbook.html
import os
import logging
from logging import StreamHandler
from logging import Formatter
LOGS_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../logs')
if not os.path.exists(LOGS_DIR):
@nkthiebaut
nkthiebaut / pandas_json_to_dataframe.py
Created March 23, 2020 20:13
Pandas : column of JSON strings to DataFrame
# inspired by https://stackoverflow.com/a/50658993/5174617
import pandas as pd
import json
df = pd.DataFrame([['0 {"a":"1","b":"2","c":"3"}'],['1 {"a" :"4","b":"5","c":"6"}']], columns=['json'])
exploded_df = df['json'].apply(json.loads).apply(pd.Series)