Skip to content

Instantly share code, notes, and snippets.

@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 1, 2021 20:22 — 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; \
}
@jaburns
jaburns / genindex.cpp
Last active March 10, 2023 18:10
Generational indices in C++ vs Rust
/*
Copyright 2021 Jeremy Burns
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR O