Skip to content

Instantly share code, notes, and snippets.

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

Felix Queißner MasterQ32

☺️
Hacking on Dunstwolke
View GitHub Profile
@MasterQ32
MasterQ32 / memory.h
Last active September 26, 2023 19:28
Useful C
#include <stdint.h>
#include <string.h>
// Usage:
// uint16_t value = read_u16_le(buffer + 3);
#define __builtin_bswap8(x) (x) // "hack"
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define int_little_to_native(_Value, _Size) (_Value)
@MasterQ32
MasterQ32 / dotfiles
Created September 25, 2023 11:40
basic dotfile manager
#!/usr/bin/env bash
set -euo pipefail
which git sed cut 1>/dev/null
timestamp="$(date +'%Y-%m-%d %H:%M')"
c_base=$'\033[0m'
@MasterQ32
MasterQ32 / ui-concept.zig
Last active December 16, 2022 17:12
Zig UI API Concept
//! xq @ UTC+2 (MasterQ32 @ GitHub) — gestern um 22:01 Uhr
//! more gui thoughts:
//!
//! i stopped using tree structures for my UIs and return to flat, ordered lists. this made the implementations sinpler by magnitudes, and one could always build stuff like a 'container' widget which would make it hierarchical by nesting UIs.
//!
//! right now, dunstwolke uses a immediate mode interface, which is now borked by a bugfix in stage2.
//!
//! now i'm thinking about how to decouple styling, layout and logic of the ui. also i'm still not sure how to manage UI events. i really dislike the callback approach of wpf/qt/winforms/...
//! compared to callbacks, immediate mode interfaces are very convenient to program, so i wonder if i can use a similar interface for a retained guy, for example a pull interface:
//! gui.pushInput(.mouse_down);
@MasterQ32
MasterQ32 / build.sh
Last active August 2, 2022 11:12
Arm 32 Kernel Example
#!/bin/bash
set -e
clear
zig build-exe -target arm-freestanding-eabi -mcpu baseline -T linker.ld -fsingle-threaded -fno-omit-frame-pointer -O ReleaseFast --name kernel kernel.zig
llvm-objdump -dt kernel
llvm-objcopy -O binary kernel kernel.bin
# cp kernel.bin disk.img
@MasterQ32
MasterQ32 / bad.zig
Created July 14, 2022 12:51
Comptime String Interning
const std = @import("std");
const input = @embedFile("input.txt");
export const capitalized = blk: {
@setEvalBranchQuota(100_000);
var result: []const []const u8 = &.{};
var iter = std.mem.tokenize(u8, input, ",.\r\n ");
@MasterQ32
MasterQ32 / atomics.zig
Created February 27, 2022 14:37
Examples of why atomics are necessary
const std = @import("std");
var global: u32 = 0;
export fn normalStore(arg: u32) void {
global = arg;
}
export fn normalLoad() u32 {
return global;
@MasterQ32
MasterQ32 / zig-packages.json
Last active February 19, 2022 10:06
Mini zpm
{
"ihex": {
"git": "https://github.com/MasterQ32/zig-ihex"
},
"args": {
"git": "https://github.com/MasterQ32/zig-args"
},
"parser-toolkit": {
"git": "https://github.com/MasterQ32/parser-toolkit"
},
@MasterQ32
MasterQ32 / Sdk.zig
Created June 14, 2021 19:14
sdkRoot()
const std = @import("std");
const Pkg = std.build.Pkg;
const Step = std.build.Step;
const FileSource = std.build.FileSource;
const GeneratedFile = std.build.GeneratedFile;
pub const Sdk = @This();
builder: *std.build.Builder,
@MasterQ32
MasterQ32 / any.zig
Created April 23, 2021 08:45
std::any implementation in zig
const std = @import("std");
pub fn main() !void {
var allocator = std.heap.page_allocator;
var a = try Any.init(allocator, @as(u32, 10));
defer a.deinit();
var b = try Any.init(allocator, @as([]const u8, "Hello, World!"));
defer b.deinit();
@MasterQ32
MasterQ32 / 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", .{