Instantly share code, notes, and snippets.
Lead developer & president of Zig Software Foundation
- Portland, Oregon
- https://andrewkelley.me/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| constbuiltin=@import("builtin"); | |
| conststd=@import("std"); | |
| constIo=std.Io; | |
| // Open two netcat instances and make them listen to these ports | |
| constrecv1_addr=Io.net.IpAddress.parseIp4("127.0.0.1",1993)catchunreachable; | |
| constrecv2_addr=Io.net.IpAddress.parseIp4("127.0.0.1",1994)catchunreachable; | |
| constaddresses: [2]Io.net.IpAddress= .{recv1_addr,recv2_addr }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDpCHl0686CO6U1HrAdDFri/N3yuNcJsfjOpXoemGOWUWpmOKiMQ24DOPxHV24H18yGtnzBlxLjw+SoTpT+0aekXMAK6r6K79dhctnUgPsxON/JmqPnag8sdrNo46d0XnCoEK2Sty3Q3GJMgtcbqsJXtwxy4h9Fv3TMVHz+NwmonEbReSM3c/jLMSZFfBXH9gUjosZ5kGtOm8DrtAxA7+YmaKYudHge1Xo/Isz+/aPHl8c5y29HKmC3PsaHP1wVBfzHEpyIdcFpNmVsD+Zu8ySeV+7zaVYPYuBB3alQHuvkjXdi5UlZVehV+FmFwFVsrQ8V1TkCvnGUWlz1PA2topZGFZ3AKRfbhG1e0mgqi8mZyN6oKDofgEJW+t3luism6c9n/PFayVePi2jLLpW0qnMpFoNeLwZp50qxRkZjLE7gZ6LeGNYj9uH11YnYEXaV3TxH5bXvlLr0DU/flsMdd5t1jq0JeluAw/k7dSHrz3/IBlS+ubdOwhdMnXk01jSUV4c= andy@Andrews-MBP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| conststd=@import("std"); | |
| constAllocator=std.mem.Allocator; | |
| constIo=std.Io; | |
| pubconststd_options:std.Options= .{ | |
| .log_level=.info, | |
| }; | |
| pubfnmain()!void { | |
| vardebug_allocator:std.heap.DebugAllocator(.{})=.init; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| pubconstGlobalVec=UniqueVec(.global); | |
| pubconstLocalVec=UniqueVec(.local); | |
| pubconstTag=enum {global,local}; | |
| fnUniqueVec(tag:Tag)type { | |
| returnstruct { | |
| pubconsttag=Tag; | |
| pubfnadd(...)@This() {... } | |
| pubfnsub(...)@This() {... } | |
| // ... |
andrewrk /zig-no-llvm.nix
CreatedApril 30, 2025 17:15
my nix-shell environment for zig development.https://github.com/ziglang/zig/wiki/How-to-build-LLVM,-libclang,-and-liblld-from-source#posix This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| withimport<nixpkgs>{};{ | |
| tmpAoeu=stdenv.mkDerivation{ | |
| name="zig-no-llvm"; | |
| hardeningDisable=["all"]; | |
| buildInputs=[ | |
| cmake | |
| ninja | |
| ]; |
andrewrk /master-output.txt
Last activeAugust 31, 2025 23:01
litmus test for restricted function pointer types This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| andy@bark ~/d/z/build-release (master) [1]> stage3/bin/zig build-obj test.zig -target avr-freestanding -OReleaseFast | |
| andy@bark ~/d/z/build-release (master)> ~/local/llvm20-assert/bin/llvm-objdump -d test.o | |
| test.o: file format elf32-avr | |
| Disassembly of section .text: | |
| 00000000 <example>: | |
| 0: 6f 92 7f 92 <unknown> | |
| 4: 8f 92 9f 92 <unknown> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| conststd=@import("std"); | |
| constassert=std.debug.assert; | |
| constAllocator=std.mem.Allocator; | |
| constIo=std.Io; | |
| pubfnmain()!void { | |
| vardebug_allocator:std.heap.DebugAllocator(.{})=.init; | |
| constgpa=debug_allocator.allocator(); | |
| //const gpa = std.heap.smp_allocator; |
andrewrk /example1-original.zig
Last activeJuly 13, 2025 01:02
programming without pointers code snippets.https://www.hytradboi.com/2025/05c72e39-c07e-41bc-ac40-85e8308f2917-programming-without-pointers This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| constState=struct { | |
| clowns:StringHashMap(Clown)=.empty, | |
| constClown=struct { | |
| scariness:f32, | |
| funniness:f32, | |
| }; | |
| fndeinit(state:*State,gpa:Allocator)void { | |
| varit=state.clowns.iterator(); |
andrewrk /test-SmpAllocator.zig
CreatedFebruary 6, 2025 11:30
an allocator test I whipped up real quick This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| conststd=@import("std"); | |
| constAllocator=std.mem.Allocator; | |
| vardebug_allocator:std.heap.DebugAllocator(.{ | |
| .safety=false, | |
| .stack_trace_frames=0, | |
| })=.init; | |
| pubfnmain()!void { | |
| //const gpa = debug_allocator.allocator(); |
NewerOlder