Skip to content

Instantly share code, notes, and snippets.

View andrewrk's full-sized avatar

Andrew Kelley andrewrk

View GitHub Profile
@andrewrk
andrewrk / readme.md
Created July 21, 2024 22:43
anatomy of fuzz tested llvm ir
$ clang -c test.c -fsanitize=fuzzer-no-link -S -emit-llvm
@andrewrk
andrewrk / 0source.zig
Created July 1, 2024 21:23
connect() hanging even after shutdown() is called
const std = @import("std");
pub fn main() !void {
const addr = try std.net.Address.initUnix("/home/andy/dev/zig/.zig-cache/tmp/b8f2350f14c91bbf");
std.log.debug("socket", .{});
const sockfd = try std.posix.socket(
std.posix.AF.UNIX,
std.posix.SOCK.STREAM | std.posix.SOCK.CLOEXEC,
0,
@andrewrk
andrewrk / child.zig
Created June 21, 2024 03:52
demo of jobserver
const std = @import("std");
pub fn main() !void {
const arena = std.heap.page_allocator;
var thread_pool: std.Thread.Pool = undefined;
try thread_pool.init(.{
.allocator = arena,
.job_server = .{ .connect = try std.net.Address.initUnix("tmp_socket") },
.n_jobs = 4,
@andrewrk
andrewrk / 0output-client.txt
Last active June 19, 2024 19:44
determining if a client can block on non-accepted connections to a server
$ ./client
info: connecting first
info: poll first
info: connecting second
info: poll second
info: connecting third (note: returns immediately)
info: poll third (note: returns immediately)
info: sleep 5 seconds
info: exit
#include "zp.h"
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv) {
zp_node root_node = zp_init();
const char *task_name = "making orange juice";
zp_node sub_node = zp_start(root_node, task_name, strlen(task_name), 5);
for (int i = 0; i < 5; i += 1) {
@andrewrk
andrewrk / demo.txt
Last active May 24, 2024 04:19
progress API test case
https://asciinema.org/a/gDna9RnicwYjDRIDn4e07NFSc
@andrewrk
andrewrk / 0example.zig
Created March 13, 2024 00:24
wait4 maxrss includes parent memory, why?
const std = @import("std");
const assert = std.debug.assert;
const expect = std.testing.expect;
pub fn main() !void {
const big = try std.heap.page_allocator.alloc(u8, 2 * 1024 * 1024 * 1024);
_ = big;
var child = std.ChildProcess.init(&.{"/usr/bin/env"}, std.heap.page_allocator);
child.stdin_behavior = .Ignore;
@andrewrk
andrewrk / instructions.ps1
Last active July 19, 2024 06:19
instructions to set up a runner
# Create a folder under the drive root
mkdir actions-runner; cd actions-runner
# Download the latest runner package
Invoke-WebRequest -Uri https://github.com/actions/runner/releases/download/v2.311.0/actions-runner-win-arm64-2.311.0.zip -OutFile actions-runner-win-arm64-2.311.0.zip
# Optional: Validate the hash
@andrewrk
andrewrk / bar.zig
Created December 19, 2023 00:26
demo of specifying different target CPU features per module. context: https://github.com/ziglang/zig/pull/18160
pub fn add(a: i32, b: i32) i32 {
return a + b;
}
@andrewrk
andrewrk / main.zig
Created December 1, 2023 21:40
advent of code 2023 day 1 part 1 in zig
const std = @import("std");
const example =
\\1abc2
\\pqr3stu8vwx
\\a1b2c3d4e5f
\\treb7uchet
;
pub fn main() !void {