Skip to content

Instantly share code, notes, and snippets.

View leecannon's full-sized avatar

Lee Cannon leecannon

View GitHub Profile
@karlseguin
karlseguin / test_runner.zig
Last active June 8, 2024 01:23
Custom Zig Test Runner
// in your build.zig, you can specify a custom test runner:
// const tests = b.addTest(.{
// .target = target,
// .optimize = optimize,
// .test_runner = b.path("test_runner.zig"), // add this line
// .root_source_file = b.path("src/main.zig"),
// });
const std = @import("std");
const builtin = @import("builtin");
partial ordering: time/events are related to each other as graphs of dependencies
total ordering: time/events are related to each other as a sequence of steps
atomic op: op which is observed to either happen fully or not at all (no in-between)
atomic variable: memory location which atomic ops happen to
data race: non-atomic ops from 2+ threads on same memory location where one op is a write
load: an atomic read to observe a value
store: an atomic write to publish a value
read-modify-write (rmw): a read, updating the value, then a write, all atomically
#!/bin/bash
set -e
ARCH="$1"
INTERVAL="$2"
CMDLINE="$3"
KERNEL="$4"
if [ -z "$ARCH" ]; then
@leecannon
leecannon / std_log.md
Last active December 14, 2023 07:29
Quick overview of Zig's `std.log`

Out of date

This is an updated fork of this gist.

A simple overview of Zig's std.log

Logging functionality that supports:

  • If a log message should be printed is determined at comptime, meaning zero overhead for unprinted messages (so just leave the code peppered with debug logs, but when it makes sense scope them; so downstream users can filter them out)
  • Scoped log messages
  • Different log levels per scope
  • Overrideable log output (write to file, database, etc.)
@ikskuh
ikskuh / async_await.zig
Last active July 11, 2022 08:41
Async Await in 60 LOC
const std = @import("std");
// usage:
fn asyncMain() !void {
// Start two interleaving tasks
var task_a = async waitUntilAndPrint(start + 1000, start + 1200, "task a");
var task_b = async waitUntilAndPrint(start + 500, start + 1300, "task b");
var task_c = async waitUntilAndPrint(start + 800, start + 1100, "task c");
await task_a;
@niklaskeerl
niklaskeerl / install_pwndbg.md
Last active June 27, 2024 22:24
Install pwndbg and gdb on arch linux

How to install pwndbg and gdb on arch linux

sudo pacman -S gdb
sudo pacman -S pwndbg
echo 'source /usr/share/pwndbg/gdbinit.py' >> ~/.gdbinit

If you are getting the following error "Cannot find Pwndbg virtualenv directory: /usr/share/pwndbg/.venv: please re-run setup.sh", do the following steps, otherwise ignore:

@ljharb
ljharb / array_iteration_thoughts.md
Last active May 22, 2024 09:22
Array iteration methods summarized

Array Iteration

https://gist.github.com/ljharb/58faf1cfcb4e6808f74aae4ef7944cff

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it mu