Skip to content

Instantly share code, notes, and snippets.

@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 / gfm-render.sh
Last active August 27, 2023 16:02
Bash script to render github flavoured markdown to HTML
#!/usr/bin/env bash
data="$(
cat "$1" \
| sed 's/"/\\"/g' \
| sed ':a;N;$!ba;s/\n/\\n/g' \
)"
if [[ -z "$2" ]]; then
context=''
@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 / 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
@jaburns
jaburns / webpack.config.js
Created April 11, 2017 22:35
Example of building only sass with webpack for legacy project
const isProduction = process.env.NODE_ENV === 'production';
module.exports = {
context: __dirname,
entry: {
styles: ['./sass/main.scss']
},
output: {
filename: 'build.css'
},
@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 / .gitconfig
Last active April 25, 2021 05:21
Using VS as mergetool on WSL
[merge]
tool = vs
[mergetool "vs"]
cmd = /home/XXX/win_merge.sh merge $LOCAL $REMOTE $BASE $MERGED
trustExitCode = false
[mergetool]
keepBackup = false
[diff]
tool = vs
[difftool "vs"]
@jaburns
jaburns / rand.js
Last active February 7, 2021 18:29
Linear congruential random-number generator.
const M = 4294967296;
const A = 1664525;
const C = 1013904223;
// seed is an integer in the range [0, M)
const next = seed => (A * seed + C) % M;
const value = seed => seed / M;
@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 ])