Skip to content

Instantly share code, notes, and snippets.

View Pangoraw's full-sized avatar
🔧
tuning

Paul Berg Pangoraw

🔧
tuning
View GitHub Profile
@Pangoraw
Pangoraw / channel.c
Last active December 4, 2020 09:19
A thread safe go channels implementation using pthreads.h
#include "channel.h"
queue_t *queue_new() {
queue_t *queue = malloc(sizeof(queue_t));
queue_init(queue);
return queue;
}
void queue_init(queue_t *queue) {
@Pangoraw
Pangoraw / image_concat.py
Created May 21, 2021 10:02
Image concat
#!python
import argparse
from PIL import Image
from torchvision import utils, transforms
def parse_args():
parser = argparse.ArgumentParser("Image concat")
parser.add_argument("inputs", metavar="input", nargs="+")
parser.add_argument("output")
@Pangoraw
Pangoraw / katex_hyper_fun.jl
Created July 7, 2021 17:57
Katex hyper fun
### A Pluto.jl notebook ###
# v0.15.0
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local el = $(esc(element))
@Pangoraw
Pangoraw / Manifest.toml
Last active May 5, 2022 19:08
Pluto test runner
# This file is machine-generated - editing it directly is not advised
julia_version = "1.7.2"
manifest_format = "2.0"
[[deps.ANSIColoredPrinters]]
git-tree-sha1 = "574baf8110975760d391c710b6341da1afa48d8c"
uuid = "a4c015fc-c6ff-483c-b24f-f7ea428134e9"
version = "0.0.1"
@Pangoraw
Pangoraw / download_zotero.py
Last active May 15, 2022 11:34
Download articles from the web when zotero has not synced them.
#!python
"""
Downloads Zotero files that are not synced on this laptop.
"""
import os
from pathlib import Path
import argparse
import sqlite3
@Pangoraw
Pangoraw / parser.py
Created December 14, 2021 19:27
A dataclass to ArgumentParser converter
"""
A small list of utilities to transform dataclasses from argparsers
"""
from typing import List, Optional
import argparse
import dataclasses
### A Pluto.jl notebook ###
# v0.17.7
using Markdown
using InteractiveUtils
# ╔═╡ bc0afc08-4320-4fdd-a09c-06c553c30db8
import Pkg
# ╔═╡ e9c29457-523f-432e-abaf-800f4c3cbb7b
@Pangoraw
Pangoraw / forward_detect_anomaly.py
Last active September 2, 2022 10:04
A helper class similar to `torch.autograd.detect_anomaly()` but for the forward pass!
from typing import Tuple
import torch
from torch import Tensor, nn
def get_hook(mod_name: str, layer_name: str, check_inf: bool = True):
def hook(_module: nn.Module, input: Tuple, output: Tuple) -> None:
for i, t in enumerate(input):
@Pangoraw
Pangoraw / eurosat.py
Created June 8, 2022 11:14
Pytorch Dataset for using the RGB version of EuroSAT
import os
from typing import Any, Callable, Tuple
import torch
from torchvision.datasets.utils import (
download_and_extract_archive,
check_integrity,
download_url,
)
from PIL import Image
@Pangoraw
Pangoraw / kappa.py
Created June 15, 2022 09:25
Online Cohen Kappa coefficient
from typing import Dict, Tuple
import torch
from torch import Tensor
class OnlineKappa:
"""
Computes an online version of the Cohen's Kappa Coefficient.