Skip to content

Instantly share code, notes, and snippets.

View keuv-grvl's full-sized avatar

Keuv Grvl keuv-grvl

  • Bordeaux, France
View GitHub Profile
import numpy as np
import pandas as pd
import seaborn as sbn
from matplotlib import pyplot as plt
from scipy.stats import anderson
from sklearn import datasets
from sklearn.cluster import MiniBatchKMeans
from sklearn.preprocessing import scale, LabelEncoder
# TODO doc, memoization
def perfboxplot(
setup,
kernels,
labels,
n=3,
xlabel="Performances",
equality_check=None,
save_path=None,
log_scale=True,
):
@keuv-grvl
keuv-grvl / .autoenv.sh
Created February 18, 2021 14:56
Autoactivate Conda env when entering a directory (using dir name or provided name).
# ln -s /path/to/this/.autoenv.sh /path/to/workdir/
if test -f .autoenv_conda_env_name ; then
TARGET_CONDA_ENV="$(cat .autoenv_conda_env_name)"
if [[ $TARGET_CONDA_ENV != $CONDA_DEFAULT_ENV ]]; then
conda activate "$TARGET_CONDA_ENV" 2&>1 2> /dev/null
fi
else
CUR_DIR=$(basename $(pwd))
conda activate "$CUR_DIR-dev" 2> /dev/null \
@keuv-grvl
keuv-grvl / wrap_tfop.py
Created October 20, 2021 08:09
Wrap TF op in Keras layer with lambda and closure
import tensorflow as tf
ReduceMean = lambda axis=1: tf.keras.layers.Lambda(lambda x: tf.reduce_mean(x, axis=axis))
i = tf.keras.layers.Input(shape=(5,15)) # shape: [BATCHSIZE, 5, 15]
m = ReduceMean(i) # shape: [BATCHSIZE, 15]
# TODO would be nice to have a wrapping function for any TF op with arbitrary
-- Learn Lua in 15 Minutes
-- Two dashes start a one-line comment.
--[[
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
----------------------------------------------------
@keuv-grvl
keuv-grvl / gradio_example.py
Created June 2, 2022 07:55
Gradio example for image classification
import gradio as gr
import numpy as np
import tensorflow as tf
import requests
# Load a classification model
model = tf.keras.applications.MobileNetV3Large(
input_shape=None,
alpha=1.0,
minimalistic=False,
@keuv-grvl
keuv-grvl / app.py
Created November 7, 2022 11:31
Add helpers to Flask to mimic fastapi decorators
from fast_flask import Flask
app = Flask(__name__)
@app.get("/users/") # equivalent to `@app.route("/users/")` from flask.Flask
def get_user_details(user_id: int = 123):
return {"123": "bob"}
if __name__ == "__main__":
@keuv-grvl
keuv-grvl / profile_with_kernprof.py
Last active April 28, 2023 06:50
Profile a fonction with cProfile
@profile
def func1(i: float):
import time
time.sleep(i)
@profile
def func_mother():
func1(1.2)
a = 2 + 3
@keuv-grvl
keuv-grvl / README.md
Created February 2, 2023 09:19
Lock and turn off your screen on Pop!_OS

(properly) Lock and turn off your screen on Pop!_OS 22.04 LTS

Pop!_OS does not turn off your screen when you lock your screen. Where you hit tue Super+L shortcut, it seems to start some screensaver which display a black image and coincidently lock your session. But the screen itself does not go to its standby mode.

Here is my solution:

  1. Nuke the <Super>l shortcut occurences:
    • List conf keys: {dconf dump / ; gsettings list-recursively } | less
  • Use dconf-editor to unset them
@keuv-grvl
keuv-grvl / demo.md
Last active February 9, 2023 16:34
(parallel) gzip qith a tqdm progress bar

gzip with tqdm progress bar

Prereq

pip install tqdm

Minimalistic