This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
# copy into /usr/bin or whatever and chmod+x | |
# example: | |
# $ gpt 'untar and ensure subdir (but no extraneous nesting)' | |
# ```bash mkdir subdir && tar -xvf archive.tar -C subdir --strip-components=1 ``` | |
# https://platform.openai.com/api-keys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Neural net implementation in PyTorch without autograd | |
# https://gist.github.com/qpwo/86c41eb6869b36dc53d5df798e66a040 | |
# based on https://gist.github.com/jessicabuzzelli/8317c2350ce63b899e0682ce256c44cf#file-image_classification_nn-py | |
# wget https://github.com/mnielsen/neural-networks-and-deep-learning/raw/master/data/mnist.pkl.gz | |
import numpy as np | |
import torch as torch | |
import gzip | |
import pickle | |
# from tqdm import tqdm_notebook as tqdm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# make a cron job | |
sudo crontab -e | |
# add this line to shutdown every day at 2:00AM: | |
# 0 2 * * * /sbin/shutdown -h now | |
# check your cron job is there: | |
sudo crontab -l | |
# the job won't run if computer is asleep. Wake up first to run it. | |
sudo pmset repeat wake MTWRFSU 01:59:00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Do `docker compose up`, then on host run: | |
# iptables -I DOCKER-USER -s 10.0.1.0/24 -o br-$INTERNAL_NETWORK_ID -j LOG_ACCEPT | |
# iptables -I DOCKER-USER -d 10.0.1.0/24 -i br-$INTERNAL_NETWORK_ID -j LOG_ACCEPT | |
# You will see the pings succeeding. | |
version: "3" | |
services: | |
proxy_cntnr: | |
container_name: proxy_cntnr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# append to .zshrc or .bashrc | |
# cd into git root | |
function gr() { | |
# check in git repo: | |
if ! git rev-parse --is-inside-work-tree &>/dev/null; then | |
echo "not in git repo" | |
return 1 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AsyncLocalStorage } from 'node:async_hooks' | |
const asyncLocalStorage = new AsyncLocalStorage<number>() | |
async function sleep(ms: number) { | |
return new Promise(resolve => setTimeout(resolve, ms)) | |
} | |
async function foo() { | |
console.log('started') | |
await sleep(1000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from contextvars import ContextVar | |
ctx = ContextVar[int]("myctx") | |
async def bar(): | |
await asyncio.sleep(1) | |
print(ctx.get(), end=" ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you have binary data or a large file that you need to copy directly | |
# from local to inside a remote docker container then you can do it like this: | |
echo fromlocal | ssh dockerhost 'docker exec -i mycontainer sh -c "cat - > /home/filename.txt"' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://gist.github.com/qpwo/5b7f068089c8a826b8a709f2fd937407 | |
const JS_MAP_MAX = Math.pow(2, 24) | |
export default class BigMap<K = unknown, V = unknown> { | |
maps: Map<K, V>[] | |
constructor(pairs: null | readonly (readonly [K, V])[]) { | |
this.maps = [new Map<K, V>(pairs)] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch as t | |
l = 2 | |
n = 3 | |
m = 5 | |
a = t.randint(0,100,(l,n)) | |
b = t.randint(0,100,(n,m)) | |
print("matmul:", a.matmul(b)) | |
print("with strides:", (a.as_strided((l,n,m), (n,1,0)) * b.as_strided((l, n, m), (0, m, 1))).sum(1)) |
NewerOlder