Skip to content

Instantly share code, notes, and snippets.

View qxcv's full-sized avatar

Sam Toyer qxcv

View GitHub Profile
@qxcv
qxcv / testing_mp_bug.ipynb
Created February 8, 2020 01:09
Testing multiprocessing-transparent numpy array
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@qxcv
qxcv / sort_pytest_durations.py
Created July 16, 2020 23:42
Sort the times produced by pytest --durations=0
# coding: utf-8
"""Some helpful functions for neatly displaying the output of `pytest
--durations=0`."""
import itertools
import re
import sys
def parse_lines(text):
results = []
for line in text.splitlines():
@qxcv
qxcv / delete_numbered_files.py
Created October 1, 2022 02:45
Find and delete large groups of files that are identical except for a single number (preserving the largest-numbered entry)
import collections
import re
import os
number_re = re.compile(r"([0-9]+)")
def number_split_permutations(filename):
for match in number_re.finditer(filename):
start, end = match.span()
prefix = filename[:start]
@qxcv
qxcv / from_gymnasium.py
Last active March 23, 2025 22:24
Gymnasium envs with Dreamer v3, along with a Minigrid example
# from_gym.py adapted to work with Gymnasium. Differences:
#
# - gym.* -> gymnasium.*
# - Deals with .step() returning a tuple of (obs, reward, terminated, truncated,
# info) rather than (obs, reward, done, info).
# - Also deals with .reset() returning a tuple of (obs, info) rather than just
# obs.
# - Passes render_mode='rgb_array' to gymnasium.make() rather than .render().
# - A bunch of minor/irrelevant type checking changes that stopped pyright from
# complaining (these have no functional purpose, I'm just a completionist who
@qxcv
qxcv / load_cuda.py
Last active June 27, 2024 22:39
CUDA library loading logic copied out of Torch's __init__.py
"""Hack to load CUDA variables shipped via PyPI. Addresses this Torch bug:
https://github.com/pytorch/pytorch/issues/101314
Copied from PyTorch's __init__.py file, with modifications:
https://github.com/pytorch/pytorch/blob/main/torch/__init__.py
Copyright notice below is from Torch.
"""