Skip to content

Instantly share code, notes, and snippets.

@leroycep
leroycep / debug output
Created May 21, 2022 22:42
debugging zig c backend duplicate typedef; https://github.com/ziglang/zig/issues/11651
new f4a0c58216b9dad9 const_slice_u8 "typedef struct { uint8_t const * ptr; size_t len; } zig_L_u8;\n"
new fd5814f465beb2c5 tuple "typedef struct {\n uintptr_t field_0;\n uint8_t field_1;\n} zig_T_tuple_7busize_2c_20u1_7d;\n"
new 8d02975f3a25a947 array_u8_sentinel_0 "typedef uint8_t zig_A_u8_5[5];\n"
new d5d7770a0890948e array_u8 "typedef uint8_t zig_A_u8_1[1];\n"
f4a0c58216b9dad9 const_slice_u8 "typedef struct { uint8_t const * ptr; size_t len; } zig_L_u8;\n"
new 4487d943b4f83aed array_u8_sentinel_0 "typedef uint8_t zig_A_u8_1[1];\n"
f4a0c58216b9dad9 const_slice_u8 "typedef struct { uint8_t const * ptr; size_t len; } zig_L_u8;\n"
f4a0c58216b9dad9 const_slice_u8 "typedef struct { uint8_t const * ptr; size_t len; } zig_L_u8;\n"
new 25da5e8e385153e6 single_const_pointer "typedef uint16_t (*zig_F__2aconst_20fn_28_29_20anyerror_21void)(void);\n"
new 3b32fc1c5510a94 optional "typedef struct { uintptr_t payload; bool is_null; } zig_Q_usize
@leroycep
leroycep / eytzinger.zig
Created November 9, 2021 13:27
Utility functions for working with Eytzinger indices
const std = @import("std");
pub fn parent(idx: u32) u32 {
std.debug.assert(idx > 0);
return (idx - 1) / 2;
}
pub fn left(idx: u32) u32 {
return 2 * idx + 1;
}
@leroycep
leroycep / forth.zig
Last active June 9, 2025 04:24 — forked from ikskuh/forth.zig
Zig Comptime Forth
const std = @import("std");
pub fn main() !void {
const argv = try std.process.argsAlloc(std.heap.page_allocator);
defer std.process.argsFree(std.heap.page_allocator, argv);
const result = forth("a b +", .{
.a = try std.fmt.parseInt(i32, argv[1], 10),
.b = try std.fmt.parseInt(i32, argv[2], 10),
});
begin
set_fill_style(FillStyle{ .Color = Color{ .r = 255, .g = 255, .b = 255, .a = 255 } })
fill_rect(0, 0, 640, 480)
set_stroke_style(FillStyle{ .Color = Color{ .r = 204, .g = 204, .b = 204, .a = 255 } })
set_line_cap(LineCap.square)
set_line_width(1.5)
set_line_dash(f32@7ffde74f5c18)
set_fill_style(FillStyle{ .Color = Color{ .r = 100, .g = 100, .b = 100, .a = 255 } })
set_fill_style(FillStyle{ .Color = Color{ .r = 100, .g = 100, .b = 100, .a = 255 } })
set_text_align(TextAlign.Left)
@leroycep
leroycep / test.wat
Created July 4, 2020 18:02
2020-07-04 zig table not exported
(module
(type (;0;) (func (param i32)))
(type (;1;) (func (param i32 i32)))
(type (;2;) (func))
(type (;3;) (func (param i32) (result i32)))
(import "env" "register" (func $register (type 0)))
(func $std.builtin.default_panic (type 1) (param i32 i32)
(local i32 i32 i32)
global.get 0
local.set 2
// 2000 lines of generated zig...
const struct_unnamed_36 = extern struct {};
pub const wasmer_instance_t = struct_unnamed_36;
// 2000 more lines of generated zig...
@leroycep
leroycep / exact-weight-random-population.py
Created April 16, 2020 15:00
Create a new population with a weighted list of parents
scores = [(0.4, "a"), (0.5, "b"), (0.1, "c")]
# Calculate the sum of all scores.
#
# Will probably be 1 since the bots are scored with a percentage,
# but just in case...
denominator = 0
for score in scores:
denominator += score[0]
nix-shell -p cmake llvmPackages_9.clang-unwrapped llvmPackages_9.llvm clang_9 libxml2 zlib pkgconfig --run fish
@leroycep
leroycep / flexbox-cheatsheet.md
Last active January 16, 2020 17:09
Flexbox Cheatsheet

Flexbox

display: flex;

A short cheatsheet for flexbox. Assembled from w3schools and [MDN][2].

@leroycep
leroycep / build.zig
Created June 30, 2019 14:17
Kind of working Raylib in zig example
const std = @import("std");
const Builder = std.build.Builder;
pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions();
var exe = b.addExecutable("game", "src/main.zig");
exe.setBuildMode(mode);
exe.addLibPath("lib");