Skip to content

Instantly share code, notes, and snippets.

View tsvikas's full-sized avatar

Tsvika Shapira tsvikas

View GitHub Profile
@tsvikas
tsvikas / joblib_parallel_with_tqdm.py
Last active June 2, 2024 22:24
joblib.Parallel, but with a tqdm progressbar
import tqdm
from joblib import Parallel
class ParallelTqdm(Parallel):
"""joblib.Parallel, but with a tqdm progressbar
Additional parameters:
----------------------
total_tasks: int, default: None
@tsvikas
tsvikas / git-folder-status.py
Last active June 5, 2024 14:36
git-folder-status: Find all subdirectories with uncommitted or unpushed code.
#!/usr/bin/env python3
# Find all subdirectories with uncommitted or unpushed code.
#
# This script scans through a directory recursively to identify the status of
# all Git repositories found within, highlighting repos with uncommitted
# changes, untracked files, or branches out of sync with their remote
# counterparts. It also identifies directories that are not Git repositories
# and branches without a remote counterpart.
# Additionally, it can fetch updates for all repositories discovered.
@tsvikas
tsvikas / rl_probe_enviroments.py
Last active January 18, 2023 23:51
Gym debugging enviroments from Andy Jones's blog
"""
based on https://andyljones.com/posts/rl-debugging.html
Documentation is quoted from that blogpost.
The usual advice to people writing RL algorithms is to use a simple environment
like the classic control ones from the Gym. Thing is, these envs have the same
problem as looking at loss curves: at best they give you a noisy indicator, and
if the noisy indicator looks poor you don't know why it looks poor. They don't
localise errors.
@tsvikas
tsvikas / pathgroup.py
Last active January 18, 2023 21:48
PathGroup is a group of python Path objects
from itertools import chain
from pathlib import Path
class PathGroup(list):
def __getitem__(self, y):
res = super().__getitem__(y)
return PathGroup(res) if (type(res) == list) else res
def glob(self, pattern):
return PathGroup(chain.from_iterable(sorted(p.glob(pattern)) for p in self))
def __getattr__(self, name):
@tsvikas
tsvikas / xr_modules.py
Created January 20, 2020 14:59
register a module (i.e. ndimage) as dataarray accessor
import functools
import xarray as xr
def register_dataarray_module(module, accessor_name=None):
if accessor_name is None:
accessor_name = module.__name__.split(".")[-1]
callable_funcs = [name for name in dir(module) if callable(getattr(module, name))]
@tsvikas
tsvikas / kernel.py
Last active January 18, 2023 21:54
manage jupyter kernels using poetry
#!/usr/bin/env python3
import getpass
import json
import re
import shutil
import socket
import subprocess
import sys
from dataclasses import dataclass, field
from pathlib import Path