Skip to content

Instantly share code, notes, and snippets.

View matu3ba's full-sized avatar

Jan Ph. H. matu3ba

View GitHub Profile
@matu3ba
matu3ba / bit_tricks.md
Last active February 1, 2023 10:48
some more bit tricks

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
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
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.
/// 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 / mkVid.sh
Created December 24, 2022 22:40
download chunklist streams (m3u8) with ffmpeg
#!/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.
# 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 / fpZig.ps1
Created December 21, 2022 23:58
Fetch and patch devkit zig
$response = Invoke-RestMethod -Uri "https://ziglang.org/download/index.json"
$downloadlink = $response.master.'x86_64-windows'.tarball
Invoke-WebRequest -Uri "$downloadlink" -OutFile "$zigdl.zip"
# TODO finish this up
@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)
# 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
@matu3ba
matu3ba / bZig.sh
Last active December 14, 2022 00:16
fetch Zig windows dev kit from WSL by parsing whats in zig git + build it (does not work due to cmake + zig not accepting unix paths on windows)
#!/usr/bin/env sh
set -e
cd /mnt/c/Users/$USER/Desktop
## start get VERSION
cd zig
# alternative: curl https://github.com/ziglang/zig/blob/master/ci/x86_64-windows.ps1
raw_version=$(grep 'ZIG_LLVM_CLANG_LLD_NAME =' ci/x86_64-windows.ps1 | cut -f3-4 -d"-")
len_version=$(echo -n $raw_version | wc -m)
# cut " from string
@matu3ba
matu3ba / builddeb.sh
Created December 3, 2022 20:26
building llvm from source scripts for Zig
#!/usr/bin/env sh
set -e
# git checkout release/15.x
# LLVM
cd llvm && mkdir -p build-deb15 && cd build-deb15
cmake .. -DLLVM_ENABLE_LIBEDIT=off -DCMAKE_INSTALL_PREFIX="${HOME}/local/llvm15deb" -DCMAKE_PREFIX_PATH="${HOME}/local/llvm15deb" -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_ENABLE_TERMINFO=OFF -G Ninja -DLLVM_PARALLEL_LINK_JOBS=1
ninja install
cd ../..