Skip to content

Instantly share code, notes, and snippets.

View scturtle's full-sized avatar
🐢

scturtle

🐢
View GitHub Profile
#!/usr/bin/env fish
function check_var -a var msg
if test -z $var; echo $msg >&2; exit 1; end
end
function check_status -a msg
if test $status != 0; echo $msg >&2; exit 1; end
end
@scturtle
scturtle / hack.js
Created April 17, 2026 07:24
change background color of gnome shell main panel based on label of input method
(async () => {
const Main = await import('resource:///org/gnome/shell/ui/main.js');
const { default: GLib } = await import('gi://GLib');
const ind = Main.panel.statusArea.keyboard;
const mgr = ind?._inputSourceManager;
if (!mgr) return;
const update = () => {
const text = ind._indicatorLabels[mgr.currentSource?.index]?.get_text();
@scturtle
scturtle / kgp.c
Created April 1, 2026 03:44
kitty graphics protocol
/* gcc -O2 -march=native -o kgp kgp.c -lm */
#define _POSIX_C_SOURCE 200809L
#include <math.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@scturtle
scturtle / qwen35.py
Last active March 6, 2026 10:12
qwen 3.5
# pip install torch huggingface_hub safetensors tokenizers transformers
import sys, re, time
from pathlib import Path
from collections import defaultdict
import torch
import torch.nn as nn
import torch.nn.functional as F
from tokenizers import Tokenizer
from safetensors import safe_open
@scturtle
scturtle / kkp.c
Created February 27, 2026 01:55
kitty keyboard protocol demo
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
struct termios orig_termios;
void reset_terminal() {
@scturtle
scturtle / mkf.py
Last active December 25, 2025 09:25
pal
from struct import pack, unpack_from
class MKFDecoder(object):
def __init__(self, path=None):
assert path or data
with open(path, "rb") as f:
self._content = memoryview(f.read())
self.count = unpack_from("<I", self._content, 0)[0] // 4
self.indexes = tuple(
@scturtle
scturtle / gemma3.py
Last active August 22, 2025 07:33
gemma3 270m
from pathlib import Path
import torch
import torch.nn as nn
import torch.nn.functional as F
from safetensors import safe_open
from tokenizers import Tokenizer
CFG = {
"vocab_size": 262_144,
"context_length": 32_768,
@scturtle
scturtle / gemma3n.py
Last active August 22, 2025 07:32
gemma3n
from dataclasses import dataclass
from pathlib import Path
import torch
from torch import nn
import torch.nn.functional as F
from safetensors import safe_open
from tokenizers import Tokenizer
@scturtle
scturtle / qwen3.py
Last active September 1, 2025 18:58
qwen3
import os
from functools import lru_cache
import torch
from torch import nn
import torch.nn.functional as F
from transformers import Qwen3Config
from transformers import Qwen2TokenizerFast
@scturtle
scturtle / mpi.py
Last active January 20, 2025 09:03
nccl in 500 LOCs
#!/usr/bin/env python3
# https://github.com/FateScript/experiments/blob/main/se/mpi/mpi.py
# https://github.com/facebookincubator/gloo/tree/main/gloo
import math
import multiprocessing
import os
import numpy as np