Skip to content

Instantly share code, notes, and snippets.

@notcancername
notcancername / bit_probabilities.zig
Last active November 13, 2025 07:32
Reads a list of newline-delimited 64-bit unsigned integer strings from stdin and outputs the bitwise probability as well as the Shannon entropy.
const std = @import("std");
pub const Result = struct {
total: u64 = 0,
counts: [64]u64 = @splat(0),
/// atomic
pub fn add(to: *Result, from: *const Result) void {
_ = @atomicRmw(u64, &to.total, .Add, from.total, .monotonic);
for (&to.counts, &from.counts) |*d, s| {
pub const std = @import("std");
pub const dvui = @import("dvui");
const Backend = dvui.backend;
pub const tardy = @import("tardy");
const Tardy = tardy.Tardy(.io_uring);
const Runtime = tardy.Runtime;
const Socket = tardy.Socket;
const Timer = tardy.Timer;
@notcancername
notcancername / floyd_steinberg.zig
Created July 5, 2025 03:28
floyd steinberg dithering
const std = @import("std");
const pnmdec = @import("pnmdec.zig");
pub fn quantFloydSteinberg(
rows: usize,
cols: usize,
out: [*]u1,
in: [*]u8,
) void {
for (0..rows) |row_cursor| {
// SPDX-License-Identifier: MPL-2.0
fn unescapeSlicePythonRepr(
out: []u8,
in: []const u8,
/// Never do output bound checks. Unsafe, use this if and only if
/// you know the string will fit (length at least input length -
/// 2)
comptime skip_bounds_check: bool,
) !usize {
@notcancername
notcancername / indexing_pool.zig
Last active February 5, 2025 19:37
A pool returning indices to be used as pointer substitutes. A limited number of items is kept in a free list to re-use.
const std = @import("std");
pub const IndexingPoolOptions = struct {
/// The maximum number of items the pool can hold.
max_items: usize = std.math.maxInt(u32),
/// The number of item indices to be kept for re-use. If this is
/// too low, items will leak until the pool is deinitialized.
free_list_len: usize = 64,
log: type = std.log.scoped(.indexing_pool),
};
#! /usr/bin/env python3
import sys
import renderdoc as rd
actions = {}
def iterDraw(d, indent = ''):
global actions
@notcancername
notcancername / spd.zig
Created November 24, 2024 16:46
change cpu speed linux zig
const std = @import("std");
pub fn put(b: []u8, a: []const u8) usize {
@memcpy(b[0..a.len], a);
return a.len;
}
pub fn main() u8 {
var ally = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer ally.deinit();
@notcancername
notcancername / sus.zig
Created November 21, 2024 12:24
risc-v emulator thing
const std = @import("std");
const assert = std.debug.assert;
const Log2Int = std.math.Log2Int;
comptime {
std.testing.refAllDeclsRecursive(@This());
}
const Register = extern union {
signed: i32,
@notcancername
notcancername / python-on-region.el
Created November 20, 2024 14:36
elisp python-on-region
(defvar
python-on-region-template
"#! /usr/bin/env python3\nimport sys\nfor line in sys.stdin:\n sys.stdout.write(line$$)\n"
"The template to use for python-on-region. $$ indicates the point.")
(defun python-on-region--run ()
(interactive)
(save-buffer)
(delete-window)
(switch-to-buffer python-on-region--buffer)
function memfrob(str) {
var out = "";
for (var i = 0; i < str.length; i++) {
out += String.fromCharCode(str.charCodeAt(i) ^ 42);
}
return out;
}
function apply(id, frobbed) {
document.getElementById(id).href = memfrob(atob(frobbed));