Skip to content

Instantly share code, notes, and snippets.

@nurpax
nurpax / kitty-keys.py
Last active October 19, 2025 13:44
Fully standalone console mode keyboard event loop (Kitty protocol)
"""
Standalone, no dependency Python code for modern keyboard and mouse handling for terminal applications.
Hardcoded for the Kitty key protocol.
Keyboard: key press, repeat, and release events.
Mouse: continuous mouse position (for hover) and click reporting.
"""
from dataclasses import dataclass
@nurpax
nurpax / test_runner.zig
Last active July 21, 2025 06:54
zig test runner
// Modded from from https://gist.github.com/karlseguin/c6bea5b35e4e8d26af6f81c22cb5d76b
// in your build.zig, you can specify a custom test runner:
// const tests = b.addTest(.{
// .target = target,
// .optimize = optimize,
// .test_runner = .{ .path = b.path("test_runner.zig"), .mode = .simple }, // add this line
// .root_source_file = b.path("src/main.zig"),
// });
//
@nurpax
nurpax / main.asm
Created February 17, 2021 17:30
text example
!use "./text" as text
!byte text("testing 123")
@nurpax
nurpax / romfont_to_64c.py
Created November 29, 2020 22:03
64c from C64 ROM font binary with some chars X'd out
import numpy as np
import sys
# C64 ROM font:
# https://github.com/nurpax/petmate/raw/master/assets/system-charset.bin
unallowed_pattern = np.array([
[1, 0, 0, 0, 0, 0, 1, 0],
[1, 1, 0, 0, 0, 1, 1, 0],
@nurpax
nurpax / customop.py
Last active November 27, 2020 22:09
nvcc problem
import torch
import torch.utils.cpp_extension
def compile():
ext_name = 'ext1'
torch.utils.cpp_extension.load(name=ext_name, sources=['ext1.cpp', 'ext1cuda.cu'], with_cuda=True, verbose=True)
def main():
compile()
#include "sokol_gfx.h"
#include <assert.h>
#include "mui_renderer.h"
#include "mui_atlas.inl"
#include "HandmadeMath.h"
#include <string.h>
#define BUFFER_SIZE 16384
import numpy as np
import math
import functools
import torch
import torch.nn as nn
from torch.nn import init
import torch.optim as optim
import torch.nn.functional as F
from torch.nn import Parameter as P
!filescope c64
!macro basic_start(addr) {
* = $801
!byte $0c, $08, $00, $00, $9e
!for d in [10000, 1000, 100, 10, 1] {
!if (addr >= d) {
!byte $30 + (addr/d)%10
}
}
@nurpax
nurpax / context.js
Last active August 10, 2019 20:39
zero page allocation context example for c64jasm
module.exports = {
create: ({}, initial) => {
const stack = [initial];
return {
push: (elt) => {
stack.push(elt)
},
pop: () => stack.pop(),
top: () => {
return stack[stack.length-1];
@nurpax
nurpax / README.md
Last active March 1, 2024 10:30
c64 size optimization -- lines

C64 "lines" size optimization contents

Deadline: midnight Finnish time on Monday, Aug 12, 2019.

Problem: make a PRG file that draws two crossing lines in C64 text mode in as few bytes as possible. The output should look exactly like this:

reference_output.png

(Note: the reference includes the black border. See the reference code for details.)