Skip to content

Instantly share code, notes, and snippets.

@jaburns
jaburns / containers.h
Created September 25, 2024 16:13
Type-safe monomorphized containers in C preprocessor (dynamic array, hashmap, generational index array)
#pragma once
// ---------- Dynarray ------------------------------------------------------------------------------------------------
#define x_DEF_DYNARRAY_SHARED(Name, V, Capacity) \
internal V Name##_pop(Name* arr) { \
if (arr->count_ == 0) PANIC("Can't pop empty dynarray"); \
return arr->data[--arr->count_]; \
} \
\
@jaburns
jaburns / main.rs
Created June 11, 2021 16:28
Rust implementation of an arithmetic coder with some basic models
// Reference: https://github.com/rygorous/gaffer_net/blob/master/main.cpp
const PROBABILITY_BITS: u32 = 15;
pub const PROBABILITY_MAX: u32 = 1 << PROBABILITY_BITS;
struct BinaryArithCoder {
lo: u32,
hi: u32,
bytes: Vec<u8>,
}
@jaburns
jaburns / server_notcached.py
Last active May 31, 2024 16:51 — forked from aallan/server_notcached.py
A non-caching version of Python's SimpleHTTPServer
#!/usr/bin/env python3
import socketserver
import http.server
PORT = 8080
class MyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
http.server.SimpleHTTPRequestHandler.end_headers(self)
@jaburns
jaburns / image_magick_window_wallpaper.py
Created February 6, 2021 06:50
Spawn a window with an image in it and follow vscode around
#!/usr/bin/env python3
import os
import subprocess
import time
import re
code_windows = subprocess.check_output("wmctrl -lx | grep 'code.Code' | cut -f1 -d' '", shell=True).decode('utf-8').strip().split('\n')
for i in range(len(code_windows)):
subprocess.Popen([ "display", '-crop', '10,10,100,100', PAPER_PATH ])
@jaburns
jaburns / png-embed.js
Created May 13, 2020 00:17
node.js code for embedded data in a png
const fs = require('fs');
const testPng = fs.readFileSync('input.png');
// ===== crc-32 ==============================================
// https://github.com/SheetJS/js-crc32/blob/master/crc32.js
function signed_crc_table() {
var c = 0, table = new Array(256);
for(var n =0; n != 256; ++n){
c = n;
@jaburns
jaburns / run.sh
Created March 14, 2020 01:59
Run Chrome in dark mode on linux
/usr/bin/google-chrome-stable --enable-features=WebUIDarkMode --force-dark-mode %U
@jaburns
jaburns / _hello.asm
Created November 3, 2019 20:43
Win32 assembly hello messagebox
global _mainCRTStartup
extern _ExitProcess@4
extern _MessageBoxA@16 ; Value after @ is size of args on stack
section .text
_mainCRTStartup:
; Setup stack to give us 4 bytes to play with
; push ebp
; sub esp, 4
@jaburns
jaburns / _source.asm
Last active October 29, 2019 21:24
Minimalist functional Windows PE file
;==================================================================================================
; Ultra-small EXE layout forked from KeyJ's console clipboard app
; https://keyj.emphy.de/win32-pe/
;
; Assembled with yasm 1.3.0 for Win64
; https://yasm.tortall.net/Download.html
;
; .\yasm-1.3.0-win64.exe -fbin -o"out.exe" source.asm
;
bits 32
@jaburns
jaburns / build.js
Last active July 18, 2019 16:25
WebGL index-based name mangling
const WEBGL_NAMES = ["ACTIVE_ATTRIBUTES","ACTIVE_TEXTURE","ACTIVE_UNIFORMS","ALIASED_LINE_WIDTH_RANGE","ALIASED_POINT_SIZE_RANGE","ALPHA","ALPHA_BITS","ALWAYS","ARRAY_BUFFER","ARRAY_BUFFER_BINDING","ATTACHED_SHADERS","BACK","BLEND","BLEND_COLOR","BLEND_DST_ALPHA","BLEND_DST_RGB","BLEND_EQUATION","BLEND_EQUATION_ALPHA","BLEND_EQUATION_RGB","BLEND_SRC_ALPHA","BLEND_SRC_RGB","BLUE_BITS","BOOL","BOOL_VEC2","BOOL_VEC3","BOOL_VEC4","BROWSER_DEFAULT_WEBGL","BUFFER_SIZE","BUFFER_USAGE","BYTE","CCW","CLAMP_TO_EDGE","COLOR_ATTACHMENT0","COLOR_BUFFER_BIT","COLOR_CLEAR_VALUE","COLOR_WRITEMASK","COMPILE_STATUS","COMPRESSED_TEXTURE_FORMATS","CONSTANT_ALPHA","CONSTANT_COLOR","CONTEXT_LOST_WEBGL","CULL_FACE","CULL_FACE_MODE","CURRENT_PROGRAM","CURRENT_VERTEX_ATTRIB","CW","DECR","DECR_WRAP","DELETE_STATUS","DEPTH_ATTACHMENT","DEPTH_BITS","DEPTH_BUFFER_BIT","DEPTH_CLEAR_VALUE","DEPTH_COMPONENT","DEPTH_COMPONENT16","DEPTH_FUNC","DEPTH_RANGE","DEPTH_STENCIL","DEPTH_STENCIL_ATTACHMENT","DEPTH_TEST","DEPTH_WRITEMASK","DITHER","DON
@jaburns
jaburns / vec.h
Created November 7, 2018 23:43
Generic variable size array in C
#pragma once
#include <stddef.h>
#include <stdlib.h>
#define Vec( T ) struct { \
size_t count; \
T *items; \
}