Skip to content

Instantly share code, notes, and snippets.

View nmichlo's full-sized avatar
🐋

Nathan nmichlo

🐋
View GitHub Profile
@nmichlo
nmichlo / array_chunking.py
Last active July 3, 2025 10:35
Torch & NumPy redistributed splitting/chunking
# BASED ON @nmichlo's ISSUE AT:
# https://github.com/pytorch/pytorch/issues/60531
# NOTE: modern features of torch and numpy make this easier to implement in python
# as modern one liners.
##### TORCH EXAMPLE #####
# chunks = 3
# dim = 0
# tensor = torch.arange(7)
@nmichlo
nmichlo / xterm_control_sequences.py
Last active July 2, 2025 13:17
XTerm Control Sequences
# XTerm Control Sequences based on:
# - https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
# ========================================================================= #
# XTerm Control Sequences from invisible-island.net as pythonic code.
# Basic control sequences are string variables.
# - eg: ESC = '\033'
# CSI = ESC + '['
# Control sequences that have args can be called to return a string.
# - eg: sgr = CSI + Ps + 'm'
@nmichlo
nmichlo / darwinkit_coreml_inference.go
Created October 25, 2024 11:10
golang coreml mlmodel & mlpackage inference example using darwinkit
package main
import (
"github.com/progrium/darwinkit/macos/coreml"
"github.com/progrium/darwinkit/macos/foundation"
"github.com/progrium/darwinkit/objc"
"log"
"unsafe"
)
@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 / colab_vscode.py
Last active October 4, 2022 09:59
Run vscode on colab!
# Adapted from https://amitness.com/vscode-on-colab
# Copy this script into a colab cell
# install deps if needed
!(command -v "code-server" 1>/dev/null) || (curl -fsSL https://code-server.dev/install.sh | sh && echo)
!(python -c "import pyngrok" 2>/dev/null) || (pip install -qqq pyngrok)
# run vscode in background if needed
!(ps -ef|awk '/code-server/&&!/awk/{exit 1}') && (nohup code-server --port 9000 --auth none &)
@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 / available_pypi_synonyms.py
Last active June 26, 2022 00:34
available pypi synonyms
# check for available pypi synonyms of a given word
# $ available_pypi_synonyms.py <words...>
import argparse
import itertools
import re
import diskcache as dc
import requests
from bs4 import BeautifulSoup