Skip to content

Instantly share code, notes, and snippets.

View afspies's full-sized avatar
🐐

Alex Spies afspies

🐐
View GitHub Profile
@afspies
afspies / inspect_json.py
Created January 22, 2025 12:03
Python function to visually inspect json structure
from typing import Any
from rich.console import Console
from rich.theme import Theme
from rich.text import Text
custom_theme = Theme({
"key": "yellow",
"type": "cyan",
"value": "green",
"tree": "bright_black",
(function (factory) {
typeof define === 'function' && define.amd ? define(factory) :
factory();
}((function () { 'use strict';
// Copyright 2018 The Distill Template Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
@afspies
afspies / iclp_schedule_spec.json
Last active May 31, 2023 22:22
ICLP Schedule Spec
{
"url": "https://calendar.google.com/calendar/ical/a0743f85a7e10fa90a0dabedbc0742ffd67995ae7ad5a8d90ed0ed35efacdf5e%40group.calendar.google.com/public/basic.ics",
"title": "ICLP 2023 Schedule",
"date": "2023-07-09",
"starting_hour": "8",
"ending_hour": "20",
"hour_division": "2",
"target": "_self",
"start_of_week": "su",
"timezone": "Europe/London",
@afspies
afspies / printarr
Last active February 26, 2023 11:23 — forked from nmwsharp/printarr
Pretty print tables summarizing properties of tensor arrays in numpy, pytorch, jax, etc.
Pretty print tables summarizing properties of tensor arrays in numpy, pytorch, jax, etc.
@afspies
afspies / q.uiver_tex_colors.tex
Created April 15, 2022 12:01
q.uiver matplotlib color scheme
// Color definitions to override the quiver web color scheme with matplotlib colors defined as tex macros
// This allows easy creation of stylistically consistent Tikz diagrams with relative ease
@afspies
afspies / gpu_allocation.py
Last active September 5, 2024 16:14
Automatic GPU Allocation
# EDIT 10/04/2022 - This version was provided by @jayelm who fixed some bugs and made the function much more robust
import os
import subprocess
import time
def assign_free_gpus(threshold_vram_usage=1500, max_gpus=2, wait=False, sleep_time=10):
"""
Assigns free gpus to the current process via the CUDA_AVAILABLE_DEVICES env variable
This function should be called after all imports,
@afspies
afspies / set_seed.py
Last active April 13, 2022 13:30 — forked from rish-16/tf_seed.py
Experiment Seeding for GPUs
import os
import numpy as np
import random
import tensorflow as tf
# from tfdeterminism import patch - only in older versions (<2?) of Tensorflow
# import torch
def seed(seed=42):
@afspies
afspies / shape_conventions.py
Created December 25, 2021 14:46
Python Library Shape Conventions
# Originally taken from Xander Steenbrugge
# cv2:
height, width, _ = img.shape
img_resized = cv2.resize(img, (new_width, new_height))
img_pixel_values = img[top:down, left:right, :]
# PIL
width, height = img.size
img_resized = img.resize((new_width, new_height))
@afspies
afspies / drawio_matplotlib_cols.yaml
Last active February 15, 2023 20:41
Draw.io Matplotlib Colorscheme
// Light Mode
{
"customColorSchemes": [[
{"fill": "#2282bc", "stroke": "none"}, // blue
{"fill": "#17c6d5", "stroke": "none"}, // cyan
{"fill": "#c4c526", "stroke": "none"}, // yellow
{"fill": "#e782c9", "stroke": "none"}, // pink
{"fill": "#9e72c5", "stroke": "none"}, // purple
{"fill": "#db2c2d", "stroke": "none"}, // red
{"fill": "#32aa32", "stroke": "none"}, // green
@afspies
afspies / gdrive_wget.sh
Created August 9, 2021 19:06
Google Drive Download
wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=FILEID' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=FILEID" -O FILENAME && rm -rf /tmp/cookies.txt