text stringlengths 32 314k | url stringlengths 93 243 |
|---|---|
const std = @import("std");
fn fib(x: u64) u64 {
if (x <= 1) return x;
return fib(x - 1) + fib(x - 2);
}
pub fn main() void {
std.debug.warn("{}", fib(47));
}
| https://raw.githubusercontent.com/drujensen/fib/578c15d13690fb36b1b3d8a419c5517c84abcd06/fib.zig |
// MIT License
// Copyright (c) 2019 Vexu
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, pub... | https://raw.githubusercontent.com/lithdew/rheia/162293d0f0e8d6572a8954c0add83f13f76b3cc6/uri.zig |
//***************************************************************************
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership. The
// ASF licenses this... | https://raw.githubusercontent.com/lupyuen/pinephone-nuttx/700afea277d94090efa3926a96352b4a6319e99f/dphy.zig |
const root = @import("root");
pub const c = if (@hasDecl(root, "loadable_extension"))
@import("c/loadable_extension.zig")
else
@cImport({
@cInclude("sqlite3.h");
@cInclude("workaround.h");
});
// versionGreaterThanOrEqualTo returns true if the SQLite version is >= to the major.minor.patch ... | https://raw.githubusercontent.com/vrischmann/zig-sqlite/91e5fedd15c5ea3cb42ccceefb3d0f4bb9bad68f/c.zig |
pub fn main() !void {
try renderer.render(.{
.Shader = SimpleBlendShader,
//.Shader = CheckerShader,
//.Shader = BandingShader,
//.Shader = CliffordAttractorShader,
//.Shader = JuliaSetShader,
//.Shader = SimplexNoiseShader,
//.Shader = GeometryShader,
... | https://raw.githubusercontent.com/quag/zig-generative-template/c59b72641ba7baef4c0f49e71f4576a67a4ec66c/main.zig |
pub const Cairo = @import("gdk/Cairo.zig");
pub const Display = @import("gdk/Display.zig").Display;
pub const Pixbuf = @import("gdk/Pixbuf.zig").Pixbuf;
pub const Wayland = @import("gdk/Wayland.zig");
fn refAllDeclsRecursive(comptime T: type) void {
comptime {
for (@import("std").meta.declarations(T)) |dec... | https://raw.githubusercontent.com/davidmhewitt/zig-gtk/8130922d5437aeb296d1f4b928d7a76f04ca27be/gdk.zig |
// Copyright (C) 2021-2024 Chadwain Holness
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
pub const token = @import("source/token.zig");
pub const Tokenizer = @import("source/Tokenizer.zig");
pub const Dom = @import("so... | https://raw.githubusercontent.com/chadwain/rem/68dcb476a9090c9bbe0044dd26914ee1266924ed/rem.zig |
const std = @import("std");
pub fn main() void {
var sum: i64 = 0;
var i: i64 = 1;
while (i <= 1000000000): (i += 1) {
sum += i;
}
std.debug.print("{any}\n", .{sum});
}
| https://raw.githubusercontent.com/clarkzjw/one-two-three...infinity/f944fe3d68923f8e2bf3e5ec75bfc53fe4e52618/Zig.zig |
pub fn puts(str: [*:0]const u8) c_int {
return asm volatile (
\\ li $9, 0x3f
\\ j 0xa0
: [ret] "={r2}" (-> c_int)
: [str] "{r4}" (str)
);
}
| https://raw.githubusercontent.com/XaviDCR92/psx-zig/d1e2090f46938fff210c3cf2d79b60b1f8e98d25/puts.zig |
const std = @import("std");
pub const json = @import("./json.zig");
const Map = json.DeserializeMap;
pub const glTF = struct {
extensionsUsed: [][]const u8 = &[_][]const u8{},
extensionsRequired: [][]const u8 = &[_][]const u8{},
accessors: []Accessor = &[_]Accessor{},
//animations: []Animation,
ass... | https://raw.githubusercontent.com/leroycep/gltf-zig/9df88e095a578fed8d456911171f3ec7110eeae4/gltf.zig |
const std = @import("std");
const data = @embedFile("./day2.data");
// const data =
// \\forward 5
// \\down 5
// \\forward 8
// \\up 3
// \\down 8
// \\forward 2
// ;
pub fn main() !void {
var it = std.mem.split(u8, data, "\n");
var x: u64 = 0;
var y: u64 = 0;
var aim: u64 = 0;
while(it.next()) |token| ... | https://raw.githubusercontent.com/IwanKaramazow/adventofcode21/0531d3835cd2fa4908829948d3800c5aee675bf4/day2.zig |
const std = @import("std");
pub fn is_alsa_playing() !bool {
var argv = [_][]const u8{ "sh", "-c", "grep RUNNING /proc/asound/card*/pcm*/sub*/status" };
var result = try std.ChildProcess.exec(.{ .allocator = std.heap.page_allocator, .argv = &argv });
// std.debug.print("stderr={s}\n", .{result.stderr});
... | https://raw.githubusercontent.com/Ryp/gpio-zig/fcca36f13cfbe0f223dcbe41b68ecb33eafd80c2/alsa.zig |
const std = @import("std");
const expect = std.testing.expect;
const test_allocator = std.testing.allocator;
test "stack" {
const string = "(()())";
var stack = std.ArrayList(usize).init(
test_allocator,
);
defer stack.deinit();
const Pair = struct { open: usize, close: usize };
var pa... | https://raw.githubusercontent.com/akalmannakarmi/zig-try/d3ed6d7e54ae8044ed760340d8139f353d3e0d3e/e4j.zig |
const std = @import("std");
pub const Format = enum {
unsigned8,
signed16_lsb,
signed24_lsb,
signed32_lsb,
pub fn getNumBytes(self: Format) u16 {
return switch (self) {
.unsigned8 => 1,
.signed16_lsb => 2,
.signed24_lsb => 3,
.signed32_lsb =>... | https://raw.githubusercontent.com/marler8997/audio-deinterlacer/9a30af1f0d8ca50155b8168773bf56763b084d44/wav.zig |
// This is free and unencumbered software released into the public domain.
pub usingnamespace @import("src/angle.zig");
pub usingnamespace @import("src/latitude.zig");
pub usingnamespace @import("src/longitude.zig");
test "Dogma" { // zig test dogma.zig
const meta = @import("std").meta;
meta.refAllDecls(@This... | https://raw.githubusercontent.com/dogmatists/dogma.zig/15c0227896fb5b37b06cd4e3386d28ca58f9a3e3/dogma.zig |
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const tomlZigName = "toml-zig";
const dep_opts = .{ .target = target, .optimize = optimize };
const tomlZig = b.dependency(tomlZigName, dep_op... | https://raw.githubusercontent.com/sirenkovladd/tinytask/3374a7fde03125e1ae07e6db6d7fcc9e43fd5083/build.zig |
const std = @import("std");
const cli = @import("cli");
const dawn = @import("dawn");
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
var port_receive_option = cli.Option{
.long_name = "port_receive",
.help = "port to receive osc messages on (optional).",
.value = cli... | https://raw.githubusercontent.com/dawnsynth/dawn/c9062931757d1df06766026b0bdac5a572ece30b/dawn.zig |
//! https://adventofcode.com/2023/day/4
const std = @import("std");
const A = std.BoundedArray(u32, 32);
fn parseWins(line: []const u8, ns: *A) !usize {
ns.len = 0;
var win_count: usize = 0;
var it = std.mem.splitScalar(u8, line, ':');
_ = it.next().?;
const x = it.next().?;
var it2 = std.mem.... | https://raw.githubusercontent.com/travisstaloch/advent-of-code-2023/e9b7cc6003191bd45bf55277567531e9e5fe9a4a/04.zig |
const root = @import("root");
pub const c = if (@hasDecl(root, "loadable_extension"))
@import("c/loadable_extension.zig")
else
@cImport({
@cInclude("sqlite3.h");
});
// versionGreaterThanOrEqualTo returns true if the SQLite version is >= to the major.minor.patch provided.
pub fn versionGreaterThan... | https://raw.githubusercontent.com/malcolmstill/clerk/06d23ad09ece6aaf74127a316d9512ff23cb883a/lib/zig-sqlite/c.zig |
const std = @import("std.zig");
const avr = @import("atmega328p.zig");
const led_pin: u8 = 5;
const loop_ms = 0x0a52;
const one_second = 63974;
fn bit(comptime b: u3) comptime u8 {
return (1 << b);
}
fn flipLed() void {
avr.portb.* ^= bit(led_pin);
}
// Timer interrupt
// When this uses callconv(.Interrupt) ... | https://raw.githubusercontent.com/ryanplusplus/avr-zig/7e240340a63d358665e04875d9cde7906d63e061/main.zig |
const std = @import("std");
pub fn insertionSort(comptime T: type, slice: []T) void {
for (1..slice.len) |i| {
var base = slice[i];
var j = i;
while (j >= 1 and slice[j - 1] > base) : (j -= 1) {
slice[j] = slice[j - 1];
}
slice[j] = base;
}
}
fn partition(co... | https://raw.githubusercontent.com/rsphing/algo.zig/66b4ddfcc48f9cd006e5f726145f2408b55a7848/sort.zig |
const std = @import("std");
const stdx = @import("./stdx.zig");
const MAX = 64;
const Stack = std.BoundedArray(u8, MAX);
const Stacks = [MAX]Stack;
const Move = struct {
from: u32,
to: u32,
count: u32,
fn parse(line: []u8) !Move {
var rest = line;
_ = stdx.cut(&rest, "move ") orelse r... | https://raw.githubusercontent.com/matklad/aoc2022/67800cfb0aa3dcb0103da06c0b6f2103f1494dc7/day5.zig |
const std = @import("std");
const testing = std.testing;
pub const SpinLock = struct {
pub const Held = struct {
self: *SpinLock,
pub fn release(held: Held) void {
@atomicStore(bool, &held.self.locked, false, .Release);
}
};
locked: bool = false,
pub fn acquire(s... | https://raw.githubusercontent.com/lithdew/hyperia/c1d166f81b6f011d9a23ef818b620e68eee3f49a/sync.zig |
// --- Day 5: Sunny with a Chance of Asteroids ---
//
// You're starting to sweat as the ship makes its way toward Mercury. The Elves suggest that you
// get the air conditioner working by upgrading your ship computer to support the Thermal
// Environment Supervision Terminal.
//
// The Thermal Environment Supervision ... | https://raw.githubusercontent.com/tiehuis/advent-of-code-2019/07f48c42d0870a7030d21c08626fcc40a447e695/5_1.zig |
const std = @import("std");
const memory_size = 1 << 16;
const program_start = 0x3000;
const Reg = enum(u16) { R0 = 0, R1, R2, R3, R4, R5, R6, R7, PC, COND, COUNT };
const Op = enum(u16) { BR = 0, ADD, LD, ST, JSR, AND, LDR, STR, RTI, NOT, LDI, STI, JMP, RES, LEA, TRAP };
const Flags = enum(u16) {
POS = 1 << 0,... | https://raw.githubusercontent.com/unbalancedparentheses/lc3-vm.zig/9de025f029e546251d0611cb750f094c33706ce7/lc3.zig |
const std = @import("std");
const Card = struct {
nr: i9,
winning_nrs: [10]i8,
nrs: [25]i8,
};
fn parseNrStr(comptime T: type, buf: []const u8) !T {
var str = std.mem.trim(u8, buf, " ");
var it = std.mem.split(u8, str, " ");
var nrs: T = undefined;
var i: usize = 0;
while (it.next()) |... | https://raw.githubusercontent.com/froehlichA/aoc2023/2335f02043a267aed2d0e35c4fc6871b08a6dac5/04/1.zig |
const std = @import("std");
const data = @embedFile("input.txt");
fn readFirstNumber(
line: []const u8,
start_index: *usize,
end_index_exclusive: *usize,
) !?u32 {
var i = end_index_exclusive.*;
while (line.len > i and !std.ascii.isDigit(line[i])) {
i += 1;
}
if (line.len <= i) {... | https://raw.githubusercontent.com/kkard2/aoc2023/6ec8e32bd8b1bc411c37748d1c2659a3b6ffec3d/04/a.zig |
const std = @import("std");
const Allocator = std.mem.Allocator;
const assert = std.debug.assert;
const VEC_SIZE_F32 = std.simd.suggestVectorSize(f32) orelse 4;
// XXX: Because of the limitation of build system in zig v0.11, we cannot
// switch between `tracy_full` and `tracy_stub` by passing compilation flags.
// So... | https://raw.githubusercontent.com/NaleRaphael/llama2.zig/3ea6b14bf7db4ccec25a50db275655f5192cd0d2/run.zig |
const std = @import("std");
const fs = std.fs;
const print = std.debug.print;
const label = [_]u8{'J', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'Q', 'K', 'A'};
const Record = struct {
hand : []u8,
bid : usize,
};
fn cmp(_:void, a:u8, b:u8) bool {
const ra = std.mem.indexOf(u8, &label, &[_]u8{a}).?;
... | https://raw.githubusercontent.com/xnhp0320/aoc2023/6e42c1e3791ba8e50c3ea0930572cade5caaef5b/7/s2.zig |
const std = @import("std");
pub fn getMimeType(path: []const u8) ?[]const u8 {
const extension = std.mem.lastIndexOf(u8, path, ".") orelse return null;
if (std.mem.eql(u8, path[extension + 1 ..], "html")) {
return "text/html";
} else if (std.mem.eql(u8, path[extension + 1 ..], "css")) {
ret... | https://raw.githubusercontent.com/hajsf/zig-server/22d3e3f821217f50e0dff9e13ee5450d221c5d30/mime.zig |
const std = @import("std");
const print = std.debug.print;
pub fn main() !void {
var file = try std.fs.cwd().openFile("data/input2.txt", .{});
defer file.close();
var reader = file.reader();
var buf: [4096]u8 = undefined;
var hpos: u32 = 0;
var ypos: u32 = 0;
var aim: u32 = 0;
while... | https://raw.githubusercontent.com/angeris/advent-of-code-2021/fcd858e08f2da93ef53a8aee0698921c896df2ec/d2-2.zig |
const std = @import("std");
const Nihilist = @import("nihilist.zig").Nihilist;
pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
var allocator = &arena.allocator;
var args = try std.process.argsAlloc(allocator);
defer std.process.argsFr... | https://raw.githubusercontent.com/stripedpajamas/nihilist/578019241123857630858161e30832788fd92e3b/main.zig |
const std = @import("std");
const g = @cImport({
@cInclude("glib-object.h");
});
pub fn main() void {
const obj1: ?*g.GObject = @alignCast(@ptrCast(g.g_object_new(g.G_TYPE_OBJECT, null)));
const obj2: ?*g.GObject = @alignCast(@ptrCast(g.g_object_new(g.G_TYPE_OBJECT, null)));
const instance1: ?*g.GType... | https://raw.githubusercontent.com/evaporei/zobject/23f6bd4c5d72ebda3da82dd189052aa1e70db985/main.zig |
pub const compare = @import("./compare.zig");
pub const meta = @import("./meta.zig");
pub const sentinel = @import("./sentinel.zig");
pub const limitslice = @import("./limitslice.zig");
// disabled for now, too many things to fix during a zig update
//pub const range = @import("./range.zig");
pub const mem = @import(".... | https://raw.githubusercontent.com/marler8997/zog/0f5f075792ba1a9c76901a9a766125386a33cce6/zog.zig |
const std = @import("std");
const libvirt = @import("libvirt");
pub fn main() !void {
std.log.info("All your codebase are belong to us.", .{});
std.log.info("libvirt version: {d}", .{libvirt.c.LIBVIR_VERSION_NUMBER});
}
| https://raw.githubusercontent.com/nektro/zig-libvirt/af019d9f5f5e51d5934b92ad539b3c50d67d0638/main.zig |
pub usingnamespace @import("src/main.zig");
pub const bun = @import("src/bun.zig");
pub const content = struct {
pub const error_js_path = "packages/bun-error/dist/index.js";
pub const error_js = @embedFile(error_js_path);
pub const error_css_path = "packages/bun-error/dist/bun-error.css";
pub const ... | https://raw.githubusercontent.com/txthinking/jb/d0e3ddce48be1ca0490904397bcd030c5aa7032e/root.zig |
//! This file is auto-generated by zpm-update and *should*
//! not be changed. This file can be checked into your VCS
//! and is able to work standalone.
const std = @import("std");
pub const pkgs = struct {
pub const ziggysynth = std.build.Pkg{
.name = "ziggysynth",
.source = .{ .path = "vendor/zi... | https://media.githubusercontent.com/media/ikskuh/zyclone/ae63975f672d9504b5cf1c9b7616454c67193500/zpm.zig |
const lua = @cImport({
@cInclude("lua.h");
@cInclude("lualib.h");
@cInclude("lauxlib.h");
});
export fn add(s: ?*lua.lua_State) c_int {
const a = lua.luaL_checkinteger(s, 1);
const b = lua.luaL_checkinteger(s, 2);
const c = a + b;
lua.lua_pushinteger(s, c);
return 1;
}
pub fn main() ... | https://raw.githubusercontent.com/tiehuis/zig-lua/bb4e2759304b4b38df10919a499528fadfe33632/main.zig |
pub extern fn add(a: i32, b: i32) i32;
pub extern fn sub(a: i32, b: i32) i32;
| https://raw.githubusercontent.com/hajsf/zig-and-go-simple-example/746c6a774a6f537a996c3d20effebc98d47ed47d/def.zig |
const expect = @import("std").testing.expect;
// 5. for loops are used to iterate over the arrays
//5. for loop
test "for loop" {
const rust_name = [_]u8{ 'r', 'u', 's', 't' }; // character literals are equivalent to integer literals
for (rust_name, 0..) |character, index| {
_ = character; //we use _ ... | https://raw.githubusercontent.com/muathendirangu/zig/9566d8190e6e980418fdd2bdcf72b418b91b8948/for.zig |
const expect = @import("std").testing.expect;
test "for" {
//character literals are equivalent to integer literals
const string = [_]u8{ 'a', 'b', 'c' };
for (string, 0..) |character, index| {
_ = character;
_ = index;
}
for (string) |character| {
_ = character;
}
... | https://raw.githubusercontent.com/wolffshots/ziglearn/5743d7a6748bf38207e5395ea0cc7b5dbdeaf230/for.zig |
const std = @import("std");
const builtin = @import("builtin");
const Self = @This();
pub const AndroidVersion = enum(u16) {
/// KitKat
android_4 = 19,
/// Lollipop
android_5 = 21,
/// Marshmallow
android_6 = 23,
/// Nougat
android_7 = 24,
/// Oreo
android_8 = 26,
/// Pie
... | https://raw.githubusercontent.com/Beyley/zig-android/63971a19b2ecc9652393d4326111cbae9de35972/sdk.zig |
// Shaders
extern fn compileShader(source: *const u8 , len: c_uint, type: c_uint) c_uint;
extern fn linkShaderProgram(vertexShaderId: c_uint, fragmentShaderId: c_uint) c_uint;
// GL
extern fn glClearColor(_: f32, _: f32, _: f32, _: f32) void;
extern fn glEnable(_: c_uint) void;
extern fn glDepthFunc(_: c_uint) void;
... | https://raw.githubusercontent.com/seflless/zig-wasm-webgl/31f726d1f2afa6256c069efb9c57d50fba2fcb90/main.zig |
const std = @import("std");
const ArrayList = std.ArrayList;
const Allocator = std.mem.Allocator;
pub fn readFile(allocator: Allocator, comptime name: []const u8) !ArrayList([]const u8) {
const file = @embedFile(name);
var lines = ArrayList([]const u8).init(allocator);
var iter = std.mem.tokenize(u8, fil... | https://raw.githubusercontent.com/boingram/advent-of-code-2023/efbebfc342c54df1c090e199b6233943d0bbee67/io.zig |
const std = @import("std");
const logger = @import("logger.zig");
const builtin = @import("builtin");
const zod = @import("zod.zig");
pub fn main() !void {
logger.log("info", "Welcome to DDoS.zig v1.00 (L7)");
const stdin = std.io.getStdIn().reader();
var inputBuffer: [101]u8 = undefined;
std.debug.pr... | https://raw.githubusercontent.com/EdamAme-x/DDoS.zig/dacd2a070ee969a6af14c5a3017e93a3ba2ca5a5/DDoS.zig |
const std = @import("std");
const flecs = @import("flecs");
const rl = @import("raylib.zig");
const components = @import("components/export.zig");
const systems = @import("systems/export.zig");
pub fn init(world: *flecs.World, allocator: *std.mem.Allocator) std.mem.Allocator.Error!void {
// add components and syst... | https://raw.githubusercontent.com/madcerto/zig-raylib-flecs-3d/328d302dbd3becbbbb89da65c01d3068f8541e80/init.zig |
const std = @import("std");
const String = @import("utils/string.zig");
pub fn main() !void {
const file = @embedFile("inputs/day1.txt");
var stringAllocator = std.heap.page_allocator;
const lines = try String.split(stringAllocator, file, "\n");
defer lines.deinit();
const numbers = [9][]const u8{... | https://raw.githubusercontent.com/kolyaventuri/advent-of-code-2023/bfec85a7c08cc11ed8bac17dcaaf7c63b4e0f4e7/day1.zig |
const std = @import("std");
const String = @import("utils/string.zig");
const Data = struct { destination: i64, range_start: i64, range_size: i64 };
fn cmpByData(_: void, a: Data, b: Data) bool {
return a.destination < b.destination;
}
pub fn main() !void {
const file = @embedFile("inputs/day5.txt");
var... | https://raw.githubusercontent.com/kolyaventuri/advent-of-code-2023/bfec85a7c08cc11ed8bac17dcaaf7c63b4e0f4e7/day5.zig |
const std = @import("std");
const mem = std.mem;
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const expectError = std.testing.expectError;
const Error = error{ Codec, Overrun };
//
//
// Deserialization
//
//
pub const Deserialize = struct {
const Self = @This();
ptr: *a... | https://raw.githubusercontent.com/rjsberry/pb.zig/a945094a18d89a97937ea83e17fd37ad281e6f65/pb.zig |
//! Matrix math operations
pub fn mul(comptime M: usize, comptime N: usize, comptime P: usize, comptime T: type, a: [N][M]T, b: [P][N]T) [P][M]T {
var res: [P][M]T = undefined;
for (&res, 0..) |*column, i| {
for (column, 0..) |*c, j| {
var va: @Vector(N, T) = undefined;
comptim... | https://raw.githubusercontent.com/leroycep/seizer/54a39bf2c2f867a2caa69c4a63fa4732ebc7ac71/src/geometry/mat.zig |
const std = @import("std");
const sort = std.sort;
const warn = std.debug.warn;
const Allocator = std.mem.Allocator;
const assert = std.debug.assert;
const Edge = struct {
from: i32,
to: i32,
distance: i32,
const Self = @This();
pub fn asc(l: Edge, r: Edge) bool {
return l.distance < r.dis... | https://raw.githubusercontent.com/Dussim/Zig/7a4da6f57cdea4f19d09f9303d1e828d542776f7/mst.zig |
const std = @import("std");
const windows = @import("windows.zig");
const ws2_32 = @import("ws2_32.zig");
const os = std.os;
const net = std.net;
const math = std.math;
const Handle = struct {
const Self = @This();
inner: windows.HANDLE,
pub fn init(handle: windows.HANDLE) Self {
return Self{ .i... | https://raw.githubusercontent.com/lithdew/afd/af5146e99443705ff5b54af8fdd88e1cd887722a/main.zig |
// This file originates from https://github.com/silversquirl/deps.zig
//
// Copyright (c) 2021 silversquirl
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, includin... | https://raw.githubusercontent.com/silversquirl/deps.zig/793f3fe2430271592590f523e99614bf215ddb5b/Deps.zig |
const std = @import("std");
const ArrayList = std.ArrayList;
const print = std.debug.print;
const Task = struct {
id: u32,
name: []const u8,
done: bool = false,
};
pub const App = struct {
task_list: ArrayList(Task),
next_id: u32,
pub fn init(allocator: std.mem.Allocator) App {
var ta... | https://raw.githubusercontent.com/cauesmelo/zig-todo/89745ced111bd523a350c810b57049985fd83c3d/app.zig |
const std = @import("std");
const lib = @import("lib.zig");
pub fn main() !void {
// const n: u16 = 0b10110000_00001111;
// const arr: [2]u8 = @bitCast(n);
// std.debug.print("{b} {b}\n", .{ arr[0], arr[1] });
// above works
const n2: u4 = 0b1011;
var arr2: [2]u2 = undefined;
const n = @t... | https://raw.githubusercontent.com/PierreV23/zig-chess-bits/3636073a1575141948c9c71bb935acbe2335a0cc/ding.zig |
const std = @import("std");
const Pair = struct {
x: usize,
y: usize,
};
pub fn Matrix(comptime T: type, width: usize, height: usize) type {
return struct {
const Self = @This();
data: [height * width]T,
pub fn width(self: Self) usize {
return width;
}
... | https://raw.githubusercontent.com/fengb/advent/dc741e527899cb22630d200bf1883ffd9356d01e/03.zig |
const std = @import("std");
const os = std.os;
const print = std.debug.print;
pub fn main() !void {
var buf: [256]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&buf);
var allocator = &fba.allocator;
const cwd = try allocator.alloc(u8, 256);
defer allocator.free(cwd);
const z = ... | https://raw.githubusercontent.com/jordanorelli/learn-zig/83479b2652b3326d482645925fc2101626d00dfd/pwd.zig |
const std = @import("std");
const warn = std.debug.warn;
const mem = std.mem;
const os = std.os;
const io = std.io;
const ArrayList = std.ArrayList;
const Map = std.AutoHashMap;
const globals = @import("globals.zig");
const atof = @import("atof.zig");
use @import("utils.zig");
... | https://raw.githubusercontent.com/cgag/crafting-interpreters-zig/8be458bd2994e9194b022e8a6439dce3455604e9/lex.zig |
const std = @import("std");
const clap = @import("clap");
const debug = std.debug;
const io = std.io;
const decompress = @import("decompress.zig");
pub fn main() !void {
var direct_allocator = std.heap.DirectAllocator.init();
var allocator = &direct_allocator.allocator;
defer direct_allocator.deinit();
... | https://raw.githubusercontent.com/BarabasGitHub/LZig4/23bdba8facb7e7def308d70610bc033a4ecd1974/main.zig |
pub fn main() u8 {
return 0;
}
| https://raw.githubusercontent.com/joachimschmidt557/zbase/907591a9f0bbf47e4e59c0bbe17e3fae69b84516/true.zig |
const std = @import("std");
pub usingnamespace @import("utils/benchmark.zig");
pub usingnamespace @import("utils/grid.zig");
pub const Map = std.AutoHashMap; | https://raw.githubusercontent.com/fjebaker/advent-of-code-2022/92aa3b1f9fc946e9946b4cb02f0737667fd06ea0/util.zig |
const std = @import("std");
const Allocator = std.mem.Allocator;
const List = std.ArrayList;
const Map = std.AutoHashMap;
const StrMap = std.StringHashMap;
const BitSet = std.DynamicBitSet;
const Str = []const u8;
const util = @import("util.zig");
const gpa = util.gpa;
const data = @embedFile("../01.txt");
pub fn ma... | https://raw.githubusercontent.com/mattias-lundell/aoc2022/ada2a442ea5fc615944d8c96534bf8b0c5afab09/01.zig |
const std = @import("std");
const assert = std.debug.assert;
pub fn RangeTo(n: usize) type {
return struct {
idx: usize,
pub fn new() RangeTo(n) {
return .{ .idx = 0 };
}
pub fn next(self: *RangeTo(n)) ?usize {
if (self.idx >= n) {
return null... | https://raw.githubusercontent.com/Nathan-Fenner/zig-net/8c04ab33577bb0ec9e4d44a645560b48330d7196/net.zig |
const std = @import("std");
fn fatal(comptime fmt: []const u8, args: anytype) noreturn {
std.log.err(fmt, args);
std.process.exit(0xff);
}
fn oom(err: std.mem.Allocator.Error) noreturn {
_ = err catch {};
@panic("Out of memory");
}
const global = struct {
var arena_instance = std.heap.ArenaAlloca... | https://raw.githubusercontent.com/marler8997/chana/3c432e223fdd61e07fed7c24a351bbf586dffc47/main.zig |
const assert = @import("std").debug.assert;
// goto is present, but should typically not be used.
// error-handling should instead be performed via defer.
test "goto" {
var value = false;
goto label;
value = true;
label:
assert(value == false);
}
| https://raw.githubusercontent.com/tiehuis/zig-notes/1ef776a684228ed1536ba54e405bfcbae586c95e/goto.zig |
const std = @import("std");
pub const pkgs = struct {
pub const zfetch = std.build.Pkg{
.name = "zfetch",
.path = .{ .path = "deps/zfetch/src/main.zig" },
.dependencies = &[_]std.build.Pkg{
std.build.Pkg{
.name = "hzzp",
.path = .{ .path = "deps/hz... | https://raw.githubusercontent.com/xyaman/ytmusic-zig/d7f9a07c8131a006e3d43213da208365d77cfd2f/deps.zig |
const std = @import("std");
const constants = @import("constants");
const print = std.debug.print;
const Snippet = @import("snippet").Snippet;
const Flags = @import("flags").Flags;
const FlagEval = @import("flags").FlagEval;
const validateFile = @import("modify_snippet").validateFile;
const checkFileExists = @import(... | https://raw.githubusercontent.com/kuro337/vsfragments/038752b30b0c21478eb62e5c1508f12b7e38b29c/main.zig |
const std = @import("std");
const mach = @import("mach");
const gpu = @import("gpu");
const App = @This();
pipeline: gpu.RenderPipeline,
queue: gpu.Queue,
pub fn init(app: *App, engine: *mach.Engine) !void {
const vs_module = engine.device.createShaderModule(&.{
.label = "my vertex shader",
.code... | https://raw.githubusercontent.com/hi7/mach-template/c2e8de108b6129d72f9b430999dabc1952972870/main.zig |
const std = @import("std");
pub const Version = std.meta.Tuple(&[_]type{ usize, usize });
pub const CompileStep = struct {
pub const base_id = .install_dir;
const Self = @This();
step: std.build.Step,
builder: *std.build.Builder,
/// Version of the Java source
source_version: Version,
//... | https://raw.githubusercontent.com/zig-java/jbt/1e314aa9530c6cfeb2ce5b4a47880dd47923da45/jbt.zig |
const std = @import("std");
const stdout = std.io.getStdOut().writer();
fn Box(comptime T: type) type {
return struct {
value: T,
};
}
const Point = struct {
X: i32 = 1,
Y: i32 = 2,
};
pub fn main() !void {
var vbox = Box(Point){
.value = undefined, // this is gonna be junk
};... | https://raw.githubusercontent.com/jordanorelli/learn-zig/83479b2652b3326d482645925fc2101626d00dfd/box.zig |
/// Showcase example usage of RexMap.
const std = @import("std");
const RexMap = @import("RexMap.zig");
pub fn main() anyerror!void {
// Get an allocator up and running
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
// Read in a file. In this case it's simply ... | https://raw.githubusercontent.com/kiedtl/zig-rexpaint/9fe0640ef61b3fd0f8b2f54f4a2b4081611bceed/main.zig |
// --- Day 6: Universal Orbit Map ---
//
// You've landed at the Universal Orbit Map facility on Mercury. Because navigation in space often
// involves transferring between orbits, the orbit maps here are useful for finding efficient
// routes between, for example, you and Santa. You download a map of the local orbits ... | https://raw.githubusercontent.com/tiehuis/advent-of-code-2019/07f48c42d0870a7030d21c08626fcc40a447e695/6_1.zig |
const builtin = @import("builtin");
const std = @import("std");
pub const OpenOptions = struct {
mode: enum { read_only, read_write } = .read_only,
};
pub fn open(dir: std.fs.Dir, path: []const u8, opt: OpenOptions) !std.fs.File {
if (builtin.os.tag == .windows) {
const path_w = try std.os.windows.sli... | https://raw.githubusercontent.com/marler8997/windows-coreutils/8368278afebd5d1edab6f04866b2868685869ae1/fs.zig |
const sprites = @import("sprites.zig");
const map = @import("map.zig");
const gfx = @import("gfx.zig");
const utils = @import("utils.zig");
const entity = @import("entity.zig");
const camera = @import("camera.zig");
pub const Sun = struct {
entity: entity.Entity,
x: f32,
y: f32,
width: f32 = 16,
h... | https://raw.githubusercontent.com/kivutar/uw8-platformer/290d1f7467fed4f6571251b9ac5fbe9351909fc5/sun.zig |
const std = @import("std");
// fn WindowReader(comptime len: usize) type {
// return struct {
// const Self = @This();
// buffer: [len]u8,
// reader: std.io.BufferedReader(4096, std.io.AnyReader),
// buffer_fullness: usize = 0,
// at_eof: bool = false,
// pub fn init(rea... | https://raw.githubusercontent.com/190n/aoc2023/1ce62583b707125a244f0c115d2f0ebb328ba7d6/1-2.zig |
const camera = @import("camera.zig");
pub extern fn blitSprite(i32, i32, i32, i32, i32) void;
pub extern fn rectangle(f32, f32, f32, f32, i32) void;
pub fn blit(spr: *const [256]u8, size: i32, x: i32, y: i32, ctrl: i32) void {
blitSprite(@intCast(@intFromPtr(spr)), size, x, y, ctrl);
}
pub const Anim = struct {
... | https://raw.githubusercontent.com/kivutar/uw8-platformer/290d1f7467fed4f6571251b9ac5fbe9351909fc5/gfx.zig |
const std = @import("std");
pub fn main() !void {
const stdin = std.io.getStdIn().reader();
const stdout = std.io.getStdOut().writer();
var buf: [32]u8 = undefined;
var score: u32 = 0;
while (try stdin.readUntilDelimiterOrEof(buf[0..], '\n')) |line| {
if (line.len == 0) continue;
... | https://raw.githubusercontent.com/matklad/aoc2022/67800cfb0aa3dcb0103da06c0b6f2103f1494dc7/day2.zig |
//! Portable Numbers
const std = @import("std");
const builtin = @import("builtin");
pub fn getIntByteSlice(comptime T: type, n: *T) []u8 {
return @ptrCast([*]u8, n)[0..@sizeOf(T)];
}
fn zigZagEncode(comptime T: type, n: T) T {
if (n >= 0) {
var k1: T = undefined;
@shlWithOverflow(T, n, 1, &k... | https://raw.githubusercontent.com/kacheproject/libkache/2039d3bcc4fc841368dde04611048c866971afcb/pn.zig |
const std = @import("std");
const Allocator = std.mem.Allocator;
const ArrayList = std.ArrayList;
const Location = @import("location.zig");
pub const Node = union(enum) {
alias: *Alias,
@"and": *And,
annotation: *Annotation,
annotation_def: *AnnotationDef,
arg: *Arg,
array_literal: *ArrayLitera... | https://raw.githubusercontent.com/FnControlOption/zig-crystal-ast/686def5c9ebf823d8f967e6dec1781697a8fcab1/ast.zig |
const std = @import("std");
const Allocator = std.mem.Allocator;
const print = @import("std").debug.print;
const Node = struct {
name: []const u8 = "",
kids: std.ArrayList(Node),
parent: ?*Node = null,
fn leaf(allocator: Allocator, name: []const u8) Node {
return parent(allocator, na... | https://raw.githubusercontent.com/ekusiadadus/msafety/c0625e3ae3d397d2a3d67f5c6e06402bf3ef6e11/walk.zig |
const std = @import("std");
const Allocator = std.mem.Allocator;
const ArrayList = std.ArrayList;
const io = @import("io.zig");
const StringHashMap = std.StringHashMap;
const Trie = @import("trie.zig").Trie;
pub fn run(allocator: Allocator) !void {
const lines = try io.readFile(allocator, "input/day1.txt");
d... | https://raw.githubusercontent.com/boingram/advent-of-code-2023/efbebfc342c54df1c090e199b6233943d0bbee67/day1.zig |
const std = @import("std");
const ArrayList = std.ArrayList;
const expect = std.testing.expect;
fn NthIterator(comptime T: type) type {
return struct {
data: []const T,
nth: usize,
index: usize = 0,
fn next(self: *NthIterator(T)) ?T {
if (self.index > self.data.len) {
... | https://raw.githubusercontent.com/fanzeyi/aoc2022/91ecf0021ebfcc3bd3ba31924af8c625ce29a526/day5.zig |
const std = @import("std");
const print = std.debug.print;
pub const ram_size = 4 * 1024; // 4 KiB
pub const rom_offset = 512;
pub const max_rom_size = ram_size - rom_offset;
pub const Error = error{
IllegalOpcode,
};
const Nibble = u4;
const DoubleNibble = struct {
x: u4,
y: u4,
};
const TripleNibble ... | https://raw.githubusercontent.com/alexandreyc/chip8-zig/0cb105a9cbab22cfc7bbf2f06ce0e79ad98cba82/c8.zig |
// zig fmt: off
const std = @import("std");
const builtin = @import("builtin");
const string = []const u8;
pub const GitExactStep = struct {
step: std.Build.Step,
builder: *std.Build,
url: string,
commit: string,
pub fn create(b: *std.Build, url: string, commit: string) *GitExactStep {
... | https://raw.githubusercontent.com/nektro/zigmod/3caa1188c9e0d926b51908e42905162b4551668a/deps.zig |
const std = @import("std");
const net = @cImport( @cInclude("netinet/in.h") );
const socket = @cImport( @cInclude("sys/socket.h") );
const cio = @cImport( @cInclude("stdio.h") );
const netdb = @cImport( @cInclude("netdb.h") );
const assert = std.debug.assert;
const warn = std.debug.warn;
const irc_port = 6667;
const... | https://raw.githubusercontent.com/tyler569/zig-irc/149757d310854922eff74b56c3e71887cf952060/irc.zig |
const std = @import("std");
// const // print = std.debug.// print;
const memEql = std.mem.eql;
const stringToEnum = std.meta.stringToEnum;
const types = @import("types.zig");
const parse = @import("parse.zig");
const Atom = types.Atom;
const AtomList = types.AtomList;
const Variable = types.Variable;
const VarList = t... | https://raw.githubusercontent.com/igmanthony/zig_comptime_lisp/67ac465a345629311f6aa96c0de1f3c698fa3964/eval.zig |
//! LVGL Module that wraps the LVGL API (incomplete)
/// Import the Zig Standard Library
const std = @import("std");
/// Import the LVGL Library from C
const c = @cImport({
// NuttX Defines
@cDefine("__NuttX__", "");
@cDefine("NDEBUG", "");
@cDefine("ARCH_RISCV", "");
@cDefine("LV_LVGL_H_INCL... | https://raw.githubusercontent.com/lupyuen/zig-lvgl-nuttx/fd4f285b181a58f9b0bc14c14aa810b1e3fcdf0c/lvgl.zig |
const std = @import("std");
const os = std.os;
const mem = std.mem;
const assert = std.debug.assert;
const warn = std.debug.warn;
const ArrayList = std.ArrayList;
const layout = @import("chunk_layout.zig");
const TypeLayout = layout.TypeLayout;
const layoutChunk = layout.layoutChunk;
const util = @import("util.zig");
... | https://raw.githubusercontent.com/SpexGuy/Zig-ECS/25479d427d6077313b37e052181369a67e389ca5/zcs.zig |
const std = @import("std");
const print = std.debug.print;
fn readIntUntilDelimiterOrEof(reader: anytype, buf: []u8, delimiter: u8) !i32 {
const maybe_int = reader.*.readUntilDelimiterOrEof(buf, delimiter) catch |err| return err;
return std.fmt.parseInt(i32, maybe_int orelse "", 0);
}
fn isOverlap(from1: i32,... | https://raw.githubusercontent.com/baboikus/advent-of-code-2022/f50080475f9ac214869b8d126fde7d38d1fd0665/4/4.zig |
const std = @import("std");
pub fn main() anyerror!void {
//Create arraylist in zig
var elves = std.ArrayList(i64).init(std.heap.page_allocator);
defer elves.deinit();
var file = try std.fs.cwd().openFile("input.txt", .{});
defer file.close();
var buf_reader = std.io.bufferedReader(file.reade... | https://raw.githubusercontent.com/mojasp/aoc_2022/2a57945b7dc5c0ad6420b81d3904fc88ae03bac7/1/1.zig |
pub export fn math(a: i32, b: i32) i32 {
return a + b;
}
| https://raw.githubusercontent.com/zigster64/bun-issue-6517/64a5dc42813b6ac209f498ea694f8b78f43c494b/add.zig |
const std = @import("std");
const builtin = @import("builtin");
const Pkg = std.build.Pkg;
const string = []const u8;
pub const cache = ".zigmod/deps";
pub fn addAllTo(exe: *std.build.LibExeObjStep) void {
checkMinZig(builtin.zig_version, exe);
@setEvalBranchQuota(1_000_000);
for (packages) |pkg| {
... | https://raw.githubusercontent.com/svc-user/zigoph/db506d6a6bee02eb587593d2326f5229902d6463/deps.zig |
// (C) 2021 Ronsor Labs.
pub inline fn tuplicate(a: u32, b: u32) u64 {
return @intCast(u64, a) << 32 | @intCast(u64, b);
}
| https://raw.githubusercontent.com/Ronsor/riscv-zig/c8522753fd44d1306cf7f827fc7b033c6ac586dc/util.zig |
const std = @import("std");
const Allocator = std.mem.Allocator;
// Parse flags from an ArgIterator according to the provided Flags struct. Skips the first arg
pub fn parse(allocator: Allocator, comptime Flags: type, args: *std.process.ArgIterator) !Flags {
std.debug.assert(args.skip());
return parseRaw(alloca... | https://raw.githubusercontent.com/silversquirl/optz/a57f38365d85a8c1151171a7e3a715ed285e2a9d/optz.zig |
const std = @import("std");
fn greaterThan(context: void, a: u32, b: u32) std.math.Order {
_ = context;
return std.math.order(a, b).invert();
}
fn printHeap(comptime T: type, gpa: std.mem.Allocator, items: []T) !void {
const binary_tree = @import("binary_tree.zig");
const printTree = @import("print_ut... | https://raw.githubusercontent.com/rsphing/algo.zig/66b4ddfcc48f9cd006e5f726145f2408b55a7848/heap.zig |
// raylib-zig (c) Nikolas Wipper 2020-2024
const std = @import("std");
const builtin = @import("builtin");
const emccOutputDir = "zig-out" ++ std.fs.path.sep_str ++ "htmlout" ++ std.fs.path.sep_str;
const emccOutputFile = "index.html";
pub fn emscriptenRunStep(b: *std.Build) !*std.Build.Step.Run {
// Find emrun.
... | https://raw.githubusercontent.com/fhlmorrison/plong/8e4dca7fe55a4c8ad4c90271e3b3230c53069a8a/emcc.zig |
const std = @import("std");
const assert = std.debug.assert;
const c = @cImport(@cInclude("zmq.h"));
pub const Context = extern struct {
raw: *anyopaque,
pub const GetOption = enum(c_int) {
io_threads = c.ZMQ_IO_THREADS,
max_sockets = c.ZMQ_MAX_SOCKETS,
socket_limit = c.ZMQ_SOCKET_LIM... | https://raw.githubusercontent.com/lacc97/zmq-z/a9f4f5a5a76e6f111f47e65cfdc6a65f81aed4de/zmq.zig |
const grid = @This();
pub fn posToIndex(comptime D: usize, strides: [D]usize, pos: [D]usize) usize {
var index: usize = 0;
for (pos, strides) |p, stride| {
index += p * stride;
}
return index;
}
pub fn Buffer(comptime D: usize, comptime T: type) type {
return BufferAligned(D, @alignOf(T), ... | https://raw.githubusercontent.com/leroycep/utils.zig/51e07120e8b05e6c5941bc53c765b072a9958c0f/grid.zig |
const std = @import("std");
// invariant: `right != null` iff `left != null`
pub fn Rope(comptime T: type) type {
return struct {
const Self = @This();
const AnyNode = union(enum) {
node: *Node,
leaf: *LeafNode,
fn destroy(node: *AnyNode, allocator: std.mem.Al... | https://raw.githubusercontent.com/SuperAuguste/random-dsa-dump/acba5f5b29106e06b372761d69a9a73622f1c063/rope.zig |
const std = @import("std");
fn fib(x: u64) u64 {
if (x <= 1) return x;
return fib(x - 1) + fib(x - 2);
}
pub fn main() void {
std.debug.warn("{}", fib(47));
}
| https://raw.githubusercontent.com/drujensen/fib/578c15d13690fb36b1b3d8a419c5517c84abcd06/fib.zig |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.