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
@keuv-grvl
keuv-grvl / python.json
Created August 5, 2024 12:30
VSCode python snippets
{
"if __name__ == \"__main__\":": {
"body": [
"if __name__ == \"__main__\":\n\t$0"
],
"prefix": [
"__name__",
"__main__",
]
},
@keuv-grvl
keuv-grvl / README.md
Last active April 18, 2023 09:55
Pytorch activation function speed

Performance for activation function

timeit applied to various Pytorch activation function on CPU and GPU, on a tensor of shape (20000,)

You must run this in a IPython session. Pytorch version is 2.0.0+cu117.

See run.py.

Results

@keuv-grvl
keuv-grvl / hf_dataset.py
Created April 12, 2023 12:33
Wrap a HF `datasets.Dataset` into `torch.utils.data.Dataset`
import torch
import datasets
class HFDataset(torch.utils.data.Dataset):
def __init__(self, dset: datasets.Dataset):
self.dset = dset
def __getitem__(self, idx):
return self.dset[idx]
@keuv-grvl
keuv-grvl / cap_screen.ipy
Last active February 21, 2023 14:09
Capture android screen from Python
%pip install pure-python-adb imageio
from ppadb.client import Client as AdbClient
# plug your android device with USB debugging
client = AdbClient(host="127.0.0.1", port=5037)
device = client.devices()[0]
screencap = device.screencap()
@keuv-grvl
keuv-grvl / bench.md
Created February 21, 2023 09:02
Benchmark device (write) speed

Benchmark write speed

Write zeros to a device (using a mountpoint).

Command

# Choose one
FOLDER="$HOME"
FOLDER="/tmp"
@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

@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 / 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 / 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 / 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,