Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

View andrewrk's full-sized avatar

Andrew Kelley andrewrk

Lead developer & president of Zig Software Foundation
View GitHub Profile
@andrewrk
andrewrk /repro.zig
Last activeOctober 23, 2025 13:08
send multiple udp messages to two different recipients
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 };
@andrewrk
andrewrk /aoeu
CreatedSeptember 11, 2025 20:24
pubkey
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDpCHl0686CO6U1HrAdDFri/N3yuNcJsfjOpXoemGOWUWpmOKiMQ24DOPxHV24H18yGtnzBlxLjw+SoTpT+0aekXMAK6r6K79dhctnUgPsxON/JmqPnag8sdrNo46d0XnCoEK2Sty3Q3GJMgtcbqsJXtwxy4h9Fv3TMVHz+NwmonEbReSM3c/jLMSZFfBXH9gUjosZ5kGtOm8DrtAxA7+YmaKYudHge1Xo/Isz+/aPHl8c5y29HKmC3PsaHP1wVBfzHEpyIdcFpNmVsD+Zu8ySeV+7zaVYPYuBB3alQHuvkjXdi5UlZVehV+FmFwFVsrQ8V1TkCvnGUWlz1PA2topZGFZ3AKRfbhG1e0mgqi8mZyN6oKDofgEJW+t3luism6c9n/PFayVePi2jLLpW0qnMpFoNeLwZp50qxRkZjLE7gZ6LeGNYj9uH11YnYEXaV3TxH5bXvlLr0DU/flsMdd5t1jq0JeluAw/k7dSHrz3/IBlS+ubdOwhdMnXk01jSUV4c= andy@Andrews-MBP
@andrewrk
andrewrk /demo.zig
Last activeJuly 18, 2025 03:35
what should be the rules of asyncConcurrent?
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;
@andrewrk
andrewrk /generic-impl-strategy.zig
CreatedJune 25, 2025 18:38
distinct vector types example
pubconstGlobalVec=UniqueVec(.global);
pubconstLocalVec=UniqueVec(.local);
pubconstTag=enum {global,local};
fnUniqueVec(tag:Tag)type {
returnstruct {
pubconsttag=Tag;
pubfnadd(...)@This() {... }
pubfnsub(...)@This() {... }
// ...
withimport<nixpkgs>{};{
tmpAoeu=stdenv.mkDerivation{
name="zig-no-llvm";
hardeningDisable=["all"];
buildInputs=[
cmake
ninja
];
@andrewrk
andrewrk /master-output.txt
Last activeAugust 31, 2025 23:01
litmus test for restricted function pointer types
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>
@andrewrk
andrewrk /example.zig
Last activeNovember 5, 2025 22:34
async await demo
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;
constState=struct {
clowns:StringHashMap(Clown)=.empty,
constClown=struct {
scariness:f32,
funniness:f32,
};
fndeinit(state:*State,gpa:Allocator)void {
varit=state.clowns.iterator();
@andrewrk
andrewrk /test-SmpAllocator.zig
CreatedFebruary 6, 2025 11:30
an allocator test I whipped up real quick
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();

[8]ページ先頭

©2009-2025 Movatter.jp