Skip to content

Instantly share code, notes, and snippets.

@qpwo
qpwo / popen-selectors-repl.py
Created November 8, 2024 17:12
repl in python with popen and selectors
# unfortunately, the stdinready event fires all the time, not just when repl ready.
# Based on https://gist.github.com/andy0130tw/39472331530d1a0e25459a547ed2c9d5
import io
import selectors
from selectors import EVENT_READ, EVENT_WRITE
import subprocess
from typing import cast
sel = selectors.DefaultSelector()
@qpwo
qpwo / mullvad-ssh.sh
Created October 23, 2024 21:55
mullvad ssh setup
sudo apt install -y nftables
sudo systemctl restart nftables.service
# https://mullvad.net/en/help/split-tunneling-with-linux-advanced
echo '
table inet excludeTraffic {
chain allowIncoming {
type filter hook input priority -100; policy accept;
@qpwo
qpwo / myvagrant.py
Created October 3, 2024 00:59
vagrant wrapper thing to make it a one-off create/destroy thingy
import os
from pathlib import Path
import json
import shutil
# 192.168.122.#{i+150}
template = """
Vagrant.configure("2") do |config|
config.vm.box = "debian/bookworm64"
# provider config
@qpwo
qpwo / both-terminals.md
Created September 18, 2024 19:34
vscode run selection in BOTH terminals
@qpwo
qpwo / full-screen-slack-thread.js
Created September 15, 2024 17:02
full screen slack thread
// full screen thread
let el = document.querySelector(".p-view_contents--secondary")
el.style.minWidth = '100vw';
el.style.minHeight = '100vh';
el.style.position = 'fixed';
el.style.top = '0';
el.style.left = '0';
el.style.margin = '0';
el.style.padding = '0';
el.style.overflow = 'auto';
@qpwo
qpwo / llama_3_405b_weight_shapes.tsv
Created September 5, 2024 19:24
llama 3.1 405b all weight shapes
We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 5 columns, instead of 1 in line 8.
name numel dtype shape path
lm_head.weight 2_101_346_304 torch.bfloat16 (128256, 16384) model-00191-of-00191.safetensors
model.embed_tokens.weight 2_101_346_304 torch.bfloat16 (128256, 16384) model-00001-of-00191.safetensors
model.layers.0.input_layernorm.weight 16_384 torch.bfloat16 (16384,) model-00003-of-00191.safetensors
model.layers.0.mlp.down_proj.weight 872_415_232 torch.bfloat16 (16384, 53248) model-00003-of-00191.safetensors
model.layers.0.mlp.gate_proj.weight 872_415_232 torch.bfloat16 (53248, 16384) model-00002-of-00191.safetensors
model.layers.0.mlp.up_proj.weight 872_415_232 torch.bfloat16 (53248, 16384) model-00002-of-00191.safetensors
model.layers.0.post_attention_layernorm.weight 16_384 torch.bfloat16 (16384,) model-00003-of-00191.safetensors
mode
@qpwo
qpwo / generate_playlist.py
Created July 25, 2024 21:27
use claude to generate unique and exquisite playlists from a seed playlist
import asyncio
import json
import os
from random import shuffle
import re
import unicodedata
from anthropic import AsyncAnthropic
import dotenv
import spotipy
@qpwo
qpwo / checkin.py
Created May 25, 2024 17:48
ai checkin script
#!/usr/bin/env python
# open lxterminal app from app launcher
# python checkinscript.py
import glob
import json
import os
from pdb import run
import time
@qpwo
qpwo / gpt.sh
Created January 3, 2024 19:32
chatgpt cli
#!/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
@qpwo
qpwo / pytorch_mnist_no_autograd.py
Last active December 22, 2023 17:17
pytorch simple feed forward net from scratch (no autograd)
# 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