Skip to content

Instantly share code, notes, and snippets.

View ikskuh's full-sized avatar
☺️
Hacking on Dunstwolke

Felix Queißner ikskuh

☺️
Hacking on Dunstwolke
View GitHub Profile
@ikskuh
ikskuh / linkerscript.zig
Created March 19, 2021 00:02
linkerscript.zig
const std = @import("std");
/// The linker here is "preloaded" with all input object files / symbols.
/// After this function is run, the linker will resolve all symbol references
/// and print all unassigned symbols (\u2192 error)
pub fn link(l: *std.link.Linker) !void {
// Creates a new output section that will be loaded into the
// same address as its virtual address. It's also a (rx!w) section
const dot_text = l.createOutputSection(".text", .{
@ikskuh
ikskuh / zig-update-git.sh
Created March 16, 2021 09:17
Zig Updater Script
#!/bin/bash
TARGET="///INVALID///"
function die()
{
if [ ! -z "${TARGET}" ]; then
rm -rf "${TARGET}"
fi
echo "$@"
@ikskuh
ikskuh / forth.zig
Created February 18, 2021 01:08
Zig Comptime Forth
const std = @import("std");
test "forwarding a value" {
const result = forth("value", .{
.value = @as(u32, 42),
});
std.testing.expectEqual(@as(u32, 42), result);
}
@ikskuh
ikskuh / interface.zig
Last active December 12, 2022 07:29
Zig Interface Implementation
const std = @import("std");
const WriterSpec = struct {
pub const write = fn(self: *@This(), msg: []const u8) error{IoError}!void;
pub const flush = fn(self: @This()) void;
};
const Writer = Interface(WriterSpec);
@ikskuh
ikskuh / closure.zig
Last active November 2, 2023 22:19
Zig Closure Implementation
const std = @import("std");
pub fn main() void {
std.log.info("mutable closure:",.{});
runMutDemo();
std.log.info("const closure:",.{});
runConstDemo();
}
@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;
const std = @import("std");
// debug switch to print all found anagrams
const print_all_results = false;
pub fn main() !void {
// arena for fast allocations
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
@ikskuh
ikskuh / event_loop.zig
Created October 25, 2020 19:39
Embedded Device Event Loop
pub fn main() !void {
SysTick.init(1_000);
EventLoop.init();
var serial_frame = async doSerialLoop();
var blinky_frame = async doBlinkyLoop();
EventLoop.run();
@ikskuh
ikskuh / build.zig
Created September 21, 2020 07:59
build.zig example
const std = @import("std");
const pkgs = struct {
const sdl2 = std.build.Pkg{
.name = "sdl2",
.path = "./lib/SDL.zig/src/lib.zig",
};
const zlm = std.build.Pkg{
.name = "zlm",
@ikskuh
ikskuh / 4k.c
Created July 3, 2020 13:34
Horrible X11 setup
#include <GL/glx.h>
#include <unistd.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <dlfcn.h>
#include <signal.h>