Skip to content

Instantly share code, notes, and snippets.

View matu3ba's full-sized avatar

Jan Ph. H. matu3ba

View GitHub Profile
@matu3ba
matu3ba / ANSI.md
Created September 1, 2023 22:06 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@matu3ba
matu3ba / cloneall.sh
Created August 1, 2023 23:48
Download various non-mainstream Kernels for (rip)grepping.
#!/usr/bin/env sh
git clone --depth=1 https://github.com/DragonFlyBSD/DragonFlyBSD
git clone --depth=1 https://github.com/freebsd/freebsd-src
git clone --depth=1 https://fuchsia.googlesource.com/fuchsia
git clone --depth=1 https://github.com/haiku/haiku
git clone --depth=1 https://github.com/hermitcore/rusty-hermit
git clone --depth=1 https://github.com/Stichting-MINIX-Research-Foundation/minix/
git clone --depth=1 https://github.com/NetBSD/src
git clone --depth=1 https://github.com/openbsd/src
@matu3ba
matu3ba / readfile.zig
Created April 27, 2023 20:07
read file
fn openAndRead(alloc: std.mem.Allocator, in_file: []const u8) !void {
var f = std.fs.cwd().openFile(in_file, .{}) catch |err| {
fatal("unable to open file '{s}': {s}\n", .{ in_file, @errorName(err) });
};
defer f.close();
const stat = try f.stat();
if (stat.size > std.math.maxInt(u32))
return error.FileTooBig;
const source = try alloc.allocSentinel(u8, @intCast(usize, stat.size), 0);
errdefer alloc.free(source);
@matu3ba
matu3ba / thead_status.diff
Created April 13, 2023 22:46
Idea for zig thread status (macos implementation idea missing and other portable questions on freebsd etc)
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig
index 8004f94d7f..22996939a3 100644
--- a/lib/std/Thread.zig
+++ b/lib/std/Thread.zig
@@ -275,6 +275,14 @@ pub fn getCurrentId() Id {
return Impl.getCurrentId();
}
+pub fn getStatus() c_int {
+ // https://stackoverflow.com/questions/9577231/how-to-check-the-state-of-linux-threads
@matu3ba
matu3ba / gist:39d3624de1779584b5cfb2cbe0853513
Last active April 15, 2023 19:46
backtracking attempt for window view creation. Code would be ugly, so dont implement.
-- Simplified version only taking into account idenically sized splits
-- along a full rectangle:
-- Windows can be grouped by following the direction of window numbers.
-- 1. 2. 3.
-- 1 | 2 | | |1 |2 | | | 6 | 1 | 2 | 3 | 4|
-- ---|---| 5 | |-----| 4 | 5 |---- |--------------|
-- 3 | 4 | | | 3 | | | 7 | 5 |
-- 1. allowed, because even though 5 has no split, it has full height
-- 2. not allowed, because 3 has no vsplit
-- 4. not allowed, because splits in 1,2 are not identical in 3.
@matu3ba
matu3ba / output_content1.txt
Last active February 15, 2023 22:50
Breaking Zigs default panic handler
Segmentation fault at address 0x3e800033cc6
/home/user/dev/git/zi/zig/master/build/stage3/lib/zig/std/os/linux/x86_64.zig:36:5: 0x22d97c in syscall2
(stacking_panics)
return asm volatile ("syscall"
^
/home/user/dev/git/zi/zig/master/build/stage3/lib/zig/std/os/linux.zig:991:49: 0x20f19f in nanosleep (sta
cking_panics)
return syscall2(.nanosleep, @ptrToInt(req), @ptrToInt(rem));
^
/home/user/dev/git/zi/zig/master/build/stage3/lib/zig/std/os.zig:5253:39: 0x20b681 in nanosleep (stacking
@matu3ba
matu3ba / aeabi.h
Created February 12, 2023 13:09 — forked from harieamjari/aeabi.h
aeabi.h declares the ARM run-time helper-function ABI for programs written in C.
/* aeabi.h - declares the ARM run-time helper-function ABI for programs written in C.
*
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
* In jurisdictions that recognize copyright laws, the author or authors
@matu3ba
matu3ba / reproduce.sh
Created February 8, 2023 20:14
sema_dump
#!/usr/bin/env sh
# Building zig in debug mode
cd zigrepo
mkdir -p build/ && cd build/ && cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH="$HOME/dev/git/bootstrap/zig-bootstrap/musl/out/host/" -GNinja && /usr/bin/time -v ninja install && cd ..
# add zig stages 3 to PATH
zig test --debug-log compilation -freference-trace --test-filter fubar arenas.zig
zig test --debug-log sema -freference-trace thread.zig
@matu3ba
matu3ba / initialization_footgun.zig
Last active February 5, 2023 19:55
Zig Result-Location-Semantics footgun
const std = @import("std");
fn t1init(alloc: std.mem.Allocator, path1: []const u8) ![]const u8 {
const stdout_wr = std.io.getStdOut().writer();
try stdout_wr.writeAll("t1init"); // prevent compiler to optimize away this fn
return try alloc.dupe(u8, path1);
}
fn t2init(alloc: std.mem.Allocator, path2: []const u8) ![]const u8 {
_ = path2;
@matu3ba
matu3ba / results.txt
Created February 1, 2023 21:48
Using c struct instead of return and writing overflow via pointer bears the same performance.
128bit
(ins)[misterspoon@pc tryzig]$ hyperfine ./addo_crt ./addo_cstruct
Benchmark 1: ./addo_crt
Time (mean ± σ): 1.083 s ± 0.006 s [User: 1.082 s, System: 0.001 s]
Range (min … max): 1.072 s … 1.094 s 10 runs
Benchmark 2: ./addo_cstruct
Time (mean ± σ): 1.077 s ± 0.003 s [User: 1.075 s, System: 0.001 s]
Range (min … max): 1.073 s … 1.082 s 10 runs