Skip to content

Instantly share code, notes, and snippets.

Avatar

matu3ba

  • Aachen
View GitHub Profile
@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.
View results.txt
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
@matu3ba
matu3ba / bit_tricks.md
Last active February 1, 2023 10:48
some more bit tricks
View bit_tricks.md

Assuming MIN < x < MAX:

trick operation/effect note
x & (x - 1) clear lowest 1 bit if result 0, then x is 2
`x (x + 1)` set lowest 0 bit
`x (x - 1)` set all bits to right of lowest 1 bit
x & (x + 1) clear all bits to right of lowest 0 bit
x & -x extract lowest 1 bit
~x &amp; (x + 1) extract lowest 0 bit (as 1 bit)
@matu3ba
matu3ba / fs.diff
Created January 22, 2023 01:59
Count Steps to Directory With Entry as diff file
View fs.diff
diff --git a/lib/std/fs.zig b/lib/std/fs.zig
index 31354a278..f06db4943 100644
--- a/lib/std/fs.zig
+++ b/lib/std/fs.zig
@@ -2085,6 +2085,44 @@ pub const Dir = struct {
}
}
+ pub const CountStepsToFolderWithEntryError = error{
+ InvalidKind,
@matu3ba
matu3ba / buildprocess.md
Created January 22, 2023 01:39
Bootstep Zig from wasm file
View buildprocess.md
wasm2.c ──────►┌──────┐   ┌──────┐   ┌────┐   ┌──────┐   ┌────┐   ┌────┐   ┌────┐
               │wasm2c│──►│zig1.c│──►│zig1│──►│zig2.c│──►│zig2│──►│zig3│──►│zig4│
          ┌───►└──────┘ ┌►└──────┘┌─►└────┘   └──────┘┌─►└────┘   └────┘   └────┘
          │  zig1.wasm ─┘         │                   │     ▲        ▲        ▲
CC ───────┴───────────────────────┴───────────────────┘     │      binary-identical
                                                            │
idealized, see TODO:                                        │(optional)
used LLVM libs ─────────────────────►┌────┐                 │
 │LLVM│─────────────────┘
@matu3ba
matu3ba / child_process.zig
Created January 9, 2023 19:15
spawnMac changes for posix_spawn that I found no use case for yet: user owns the actions + attribute or users doesnt.
View child_process.zig
/// Use this for additional posix spawn attributes.
/// Do not set spawn attribute flags and do not modify stdin, stdout, stderr
/// behavior, because those are set in the platform-specific spawn method.
posix_attr: if (os.hasPosixSpawn) ?os.posix_spawn.Attr else void,
posix_actions: if (os.hasPosixSpawn) ?os.posix_spawn.Actions else void,
.posix_attr = if (os.hasPosixSpawn) null else undefined,
.posix_actions = if (os.hasPosixSpawn) null else undefined,
@matu3ba
matu3ba / plan.txt
Last active January 5, 2023 10:53
plan to end distro hopping
View plan.txt
nice project: fnarg_trace for zig
for now:
1. first: endeavour + kde
2. secondary: nixOS + river (new laptop/pc?)
next:
1. main driver: nixOS + river
2. secondary: nixOS + river + s6 instead of systemd
3. Think of something pulling less dependency cruft than `cachix/devsetup`.
@matu3ba
matu3ba / zig_cache.md
Last active January 4, 2023 08:43
Big picture of the Zig caching system.
View zig_cache.md

This is outdated now. Compilation does not use the tmp directory anymore.

** Big picture of the Zig caching system. ** This is a big picture of the Zig caching system, mostly motivated for me to understand the necessary bits to solve ziglang/zig#11643. It reflects the status quo of commit fcfeafe99a3ecc694a3475735c81a0d75b6da6d0. The core logic is defined in src/Cache.zig.

zig-cache/h contains the manifest files with varying content.

@matu3ba
matu3ba / mkVid.sh
Created December 24, 2022 22:40
download chunklist streams (m3u8) with ffmpeg
View mkVid.sh
#!/usr/bin/env sh
#sript to download chunklist streams videos
#ffmpeg -i "url_path_to_file.m3u8" -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 file.mp4
ffmpeg -i "uri/chunklist_somehash.m3u8" -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 file.mp4
@matu3ba
matu3ba / bZig.ps1
Created December 22, 2022 00:01
Build Zig with previous Zig version by parsing devkit.
View bZig.ps1
# powershell script to parse devkit version and install Zig
# assume: 1. devkit in dir devkit, zig in dir zig in same dir
# 2. powershell scripts executable (execution in shell):
# Get-Content bZig.ps1 | PowerShell.exe -noprofile -
# parse pip install
$draftpathninja = pip show ninja
$pathninja = $draftpathninja[7].Split(" ")[1]
$joinpath = -join($pathninja, "\ninja\data\bin")
$env:Path += $joinpath
@matu3ba
matu3ba / bZigCmakeNinja.ps1
Last active December 21, 2022 23:59
Powershell script to parse devkit version + ninja install path and building (failing with CMAKE_AR-NOTFOUND)
View bZigCmakeNinja.ps1
# powershell script to parse devkit version and install Zig
# assume: 1. devkit in dir devkit, zig in dir zig in same dir
# 2. cmake installed (download possible on https://cmake.org/download/)
# 3. ninja installed (pip install ninja) + in path
# 4. powershell scripts executable (execution in shell):
# Get-Content bZig.ps1 | PowerShell.exe -noprofile -
## current error:
#[10/21] Linking CXX static library zigcpp\libzigcpp.a
#FAILED: zigcpp/libzigcpp.a