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
@marler8997
marler8997 / induce.zig
Created April 22, 2026 16:34
Zig 0.16.0 Missing Windows Network Errors
//! Minimal repro for three NTSTATUS codes that stdlib's AFD-based socket
//! functions should map but currently fall through to `windows.unexpectedStatus`:
//!
//! netConnectIpWindows / AFD.CONNECT: CONNECTION_REFUSED (0xc0000236)
//! netReadWindows / AFD.RECEIVE: CONNECTION_RESET (0xc000020d)
//! netWriteWindows / AFD.SEND: CONNECTION_RESET (0xc000020d)
//!
//! On an unpatched stdlib each scenario prints the raw NTSTATUS via
//! std.options.unexpected_error_tracing and surfaces `error.Unexpected`.
//! On a patched stdlib each scenario surfaces a specific Zig error
@marler8997
marler8997 / hello.zig
Last active April 16, 2026 03:40
zigx v libxcb
const std = @import("std");
const x11 = @import("x11");
const window_width = 400;
const window_height = 400;
const Ids = struct {
range: x11.IdRange,
pub fn window(self: Ids) x11.Window {
return self.range.addAssumeCapacity(0).window();
@marler8997
marler8997 / opaque_concrete.diff
Created November 6, 2025 16:46
C++ Opaque Concrete Pattern
diff --git a/linux/src/Engine.cpp b/linux/src/Engine.cpp
index 41481be07..9a413e412 100644
--- a/linux/src/Engine.cpp
+++ b/linux/src/Engine.cpp
@@ -117,6 +117,24 @@ namespace
std::vector<std::string> slugs;
} global_personal_call_url;
+
+ // defines conversion functions between the "opaque types" used by zig
const std = @import("std");
const win32 = @import("win32").everything;
const root = @import("root");
const audio = @import("audio.zig");
fn u32FromHr(hr: i32) u32 {
return @bitCast(hr);
}
pub fn processWarmup() !void {
#pragma once
#include <cstdint>
#include <optional>
enum class ReleaseMouseButtons { No, Yes };
struct SendMousePos { int32_t x; int32_t y; };
void send_mouse_move(std::optional<SendMousePos> pos, ReleaseMouseButtons);
void send_mouse_button(uint32_t button_flags);
void send_mouse_scrolls(bool precise, float delta_x, float delta_y);

Build LLVM for Zig on Windows

> mkdir c:\llvm20
> cd c:\llvm20

Install MSVC Build Tools

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 {