Skip to content

Instantly share code, notes, and snippets.

View nickelca's full-sized avatar

Chase Nickel nickelca

View GitHub Profile
@nickelca
nickelca / asm_dsl.zig
Last active January 21, 2025 03:12
x86 assembly dsl in zig
comptime {
const builtin = @import("builtin");
std.debug.assert(builtin.target.cpu.arch == .x86);
}
pub const Instruction = union(enum) {
mov_: Mov,
int_: Int,
ret_: Ret,
lea_: Lea,
@nickelca
nickelca / hashmap_json.zig
Last active December 28, 2024 08:25
Parse json string into std.StringHashMap using std.json.parseFromSliceLeaky.
pub fn main() !void {
var arena_state: std.heap.ArenaAllocator = .init(std.heap.page_allocator);
defer arena_state.deinit();
const arena = arena_state.allocator();
const parsed = try std.json.parseFromSliceLeaky(Meow, arena,
\\{
\\ "name": "My name",
\\ "map": {
\\ "a": 1,
@nickelca
nickelca / Text_Object.zig
Last active December 15, 2024 23:18
Text components with std.json parsing
const Text_Object = @This();
list: []const Text,
pub const Text = union(enum) {
component: Component,
plain: []const u8,
pub fn jsonParse(
ally: std.mem.Allocator,
@nickelca
nickelca / flags.txt
Created March 1, 2024 01:24
List of flags for syscall and C std functions
--protection
PROT_NONE: 0b000
PROT_READ: 0b001
PROT_WRITE: 0b010
PROT_EXEC: 0b100
--map flags
MAP_SHARED: 0b000001 Share mapping with all process mapped to this object. Chages made will be written to file
MAP_PRIVATE: 0b000010 Mapping not shared with other processes. Changes made will not be written to file
MAP_FIXED: 0b010000 System is forced to use exact mapping address specified. Fail if not possible