Skip to content

Instantly share code, notes, and snippets.

@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));
@notcancername
notcancername / gist:5f17a6a6ec7a587b1df27edef506fef2
Created September 20, 2024 17:59
random bit generator in c
struct random_bit_generator {
uint32_t word;
uint8_t bits_remaining;
};
static bool next_bit(struct random_bit_generator *rbg) {
if (rbg->bits_remaining == 0) {
rbg->word = arc4random();
rbg->bits_remaining = 32;
}
@notcancername
notcancername / passgen.zig
Last active August 28, 2024 17:22
passphrase generator, with adjustable entropy
const std = @import("std");
const delimiter = '\n';
const default_bits = 64;
const Wordlist = struct {
bytes: std.ArrayListUnmanaged(u8),
word_indices: std.ArrayListUnmanaged(usize),
allocator: std.mem.Allocator,
@notcancername
notcancername / size_report.zig
Created August 5, 2024 20:11
zig function to report on the size of containers
const std = @import("std");
pub fn sizeReport(comptime T: type, comptime indent: []const u8) []const u8 {
comptime {
var result: []const u8 = "";
result = result ++ std.fmt.comptimePrint("{s}size of {s} is {d} bytes ({d} bits)\n", .{indent, @typeName(T), @sizeOf(T), @bitSizeOf(T)});
switch (@typeInfo(T)) {
.Struct => |s| {
result = result ++ std.fmt.comptimePrint("{s}field report ({s}):\n", .{indent, @tagName(s.layout)});
for (s.fields) |field| {
@notcancername
notcancername / rc4.zig
Created July 29, 2024 14:28
random RC4 implementation I wrote at some point
pub const Rc4 = struct {
s: [256]u8 = undefined,
i: u8 = 0,
j: u8 = 0,
pub fn init(key: []const u8) Rc4 {
var self = Rc4{};
for(&self.s, 0..) |*c, i| c.* = @intCast(i);