Skip to content

Instantly share code, notes, and snippets.

View marler8997's full-sized avatar

Jonathan Marler marler8997

  • Tuple
  • Idaho, United States
View GitHub Profile
import argparse
import datetime
import hashlib
import filecmp
import glob
import json
import os
import pathlib
import re
import shutil
static LRESULT CALLBACK LoggingWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
MsgNode msg_node;
WndProcEnter(&msg_node, hwnd, msg, wparam, lparam);
if (false) {
char buf[1000];
FormatMessages(buf, 0, sizeof(buf), &msg_node);
TRACELOG(LOG_INFO, "WndProc: %s", buf);
}
LRESULT result = ActualWndProc(hwnd, msg, wparam, lparam);
@marler8997
marler8997 / stack.zig
Created March 30, 2025 00:34
An interesting way to do stack allocation in Zig
const std = @import("std");
pub const Params = struct {
Return: type,
Args: type,
};
pub fn with(
comptime T: type,
comptime params: Params,
@marler8997
marler8997 / perftest.zig
Last active March 23, 2025 16:29
PerfTest
// perftest.zig
//
// build with | zig build-exe -O ReleaseFast perftest.zig
// linux test | poop "./perftest std" "./perftest custom"
//
const std = @import("std");
const tokens = @embedFile("tokens.zig");
pub fn main() void {
@marler8997
marler8997 / build.zig
Created January 11, 2025 02:37
Zig Refterm Colored Cells Example
const std = @import("std");
const builtin = @import("builtin");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const win32_dep = b.dependency("win32", .{});
const win32_mod = win32_dep.module("zigwin32");
const exe = b.addExecutable(.{
.name = "example",
.root_source_file = b.path("example.zig"),
fn hns_from_filetime(filetime: win32.FILETIME) u64 {
return @as(u64, filetime.dwLowDateTime) |
(@as(u64, filetime.dwHighDateTime) << 32);
}
const TimeFmt = struct {
hns: u64,
pub fn format(
self: TimeFmt,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,

Zig Boolean Enums

Some of my thoughts on using enums in place of bool, adding a way to opt-in to an implicit conversion could have some benefits.

Zig enums provide a convenient way to represent dual-state values (booleans) with domain-specific names. An example of this is std.builtin.Signedness:

const Signedness = enum { unsigned, signed };

Lazy Dependencies Today

  • Configure build (build.zig's build fn is invoked)
  • If lazyDependency is ever called during configuration, exit the build runner and resolve the missing dependencies and rebuild/rexecute

Example Usage:

const foo_enabled = b.option(bool, "foo", "Enable foo stuff") orelse false;
if (foo_enabled) {
 if (b.lazyDependency("foo", .{})) |foo_dep| {
const std = @import("std");
const Build = std.Build;
fn oom(e: error{OutOfMemory}) noreturn {
std.log.err("{s}", .{@errorName(e)});
@panic(@errorName(e));
}
const LibraryDependency = struct {
lib: *Library,
const SystemHandleInformation = 16;
pub extern "ntdll" fn NtQuerySystemInformation(
SystemInformationClass: i32,
SystemInformation: ?*anyopaque,
SystemInformationLength: u32,
ReturnLength: ?*u32,
) callconv(@import("std").os.windows.WINAPI) win32.NTSTATUS;
const SYSTEM_HANDLE = extern struct {