Skip to content

Instantly share code, notes, and snippets.

View nmichlo's full-sized avatar
🐋

Nathan nmichlo

🐋
View GitHub Profile
@nmichlo
nmichlo / Monokai.itermcolors
Last active February 27, 2024 21:58
iterm2 monokai ANSI colours [Original+Dark+Light] ⭐️ Dark
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Alpha Component</key>
<real>1</real>
<key>Blue Component</key>
<real>0.066666670143604279</real>
@nmichlo
nmichlo / cloudflare-ddns-update.sh
Created September 2, 2022 14:00 — forked from foobarhl/cloudflare-ddns-update.sh
A bash script to update a Cloudflare DNS A record with the external IP of the source machine
#!/bin/bash
# A bash script to update a Cloudflare DNS A record with the external IP of the source machine
# Used to provide DDNS service for my home
# Needs the DNS record pre-creating on Cloudflare
## Based on https://gist.github.com/Tras2/cba88201b17d765ec065ccbedfb16d9a with updates to use
## per-zone configurable access tokens available in the API sections of your Cloudflare profile
## - info@foo-games.com
@nmichlo
nmichlo / python_container_bench.py
Last active July 28, 2022 11:17
python basic container types benchmark
"""
Benchmark of different python calls:
TL;DR:
- don't use dict(), dataclasses or namedtuples
- use {...}, [...], (...)
- tuples are fastest
- args are faster than kwargs for dataclasses and namedtuples
RESULTS:
@nmichlo
nmichlo / python_orm_bench.py
Last active July 28, 2022 10:25
python sqlite orm benchmark
"""
py3.8 - macbook pro 16-inch, 2019, 2.3 GHz 8-Core Intel Core i9, 16 GB 2667 MHz DDR4
In memory benchmarks, working with 100_000 items at a time
SqlAlchemy - insert bulk: 1560.605ms
SqlAlchemy - select all: 1350.774ms
SqlAlchemy - insert singles: 7821.888ms
sqlite3 - insert singles: 140.412ms
@nmichlo
nmichlo / export_google_drive_folder.py
Last active July 19, 2022 10:31
Script to start an export job for a google drive folder and then download it.
# MIT LICENSE
# Nathan Michlo
"""
Script to bypass rate limits for a GoogleDrive file
by creating an export job for the parent folder.
1. User manually specifies the file id of this parent folder
2. Script starts an export job for this folder
3. Script polls and waits for completion of the export job
@nmichlo
nmichlo / torchsort_dims.py
Created March 14, 2022 13:10
torchsort but allow specifying the dimension
from functools import lru_cache
from typing import Tuple
from typing import Union
import numpy as np
import torch
# ========================================================================= #
@nmichlo
nmichlo / nd_ordered_dithering.py
Last active June 22, 2022 23:43
N-Dimensional Ordered Dithering
# ordered dithering generalised to n dims
# 2x2 example:
# ■ ■ | □ ■ | □ ■ | □ □ | □ □
# ■ ■ | ■ ■ | ■ □ | ■ □ | □ □
# ~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
# MIT License
#
# Copyright (c) 2021 Nathan Juraj Michlo
@nmichlo
nmichlo / ordered_dithering.py
Created August 23, 2021 16:41
Ordered Dithering
@functools.lru_cache()
def dither_matrix(n: int):
assert isinstance(n, int) and (n > 0)
if n == 1:
return np.array([[0]])
matrix = (1/n**2) * np.asarray(np.bmat([
[n**2 * dither_matrix(int(n/2)) + 0, n**2 * dither_matrix(int(n/2)) + 2],
[n**2 * dither_matrix(int(n/2)) + 3, n**2 * dither_matrix(int(n/2)) + 1],
]))
matrix.flags.writeable = False # because we are caching this
@nmichlo
nmichlo / check_cyclic.py
Created August 2, 2021 10:26
Check for cyclic dependencies in a python project
# ~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
# MIT License
#
# Copyright (c) 2021 Nathan Juraj Michlo
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
@nmichlo
nmichlo / tasks.py
Created July 27, 2021 10:58
task handler
import dataclasses
import inspect
from functools import lru_cache
from typing import Any
from typing import Dict
from typing import Set
from typing import Tuple
from typing import Union