Skip to content

Instantly share code, notes, and snippets.

View ashafq's full-sized avatar

Ayan Shafqat ashafq

View GitHub Profile
@codebrainz
codebrainz / c99.l
Created June 14, 2012 23:49
C99 Lex/Flex & YACC/Bison Grammars
D [0-9]
L [a-zA-Z_]
H [a-fA-F0-9]
E ([Ee][+-]?{D}+)
P ([Pp][+-]?{D}+)
FS (f|F|l|L)
IS ((u|U)|(u|U)?(l|L|ll|LL)|(l|L|ll|LL)(u|U))
%{
#include <stdio.h>
@aallan
aallan / mac-vendor.txt
Last active May 11, 2025 20:59
List of MAC addresses with vendors identities
000000 Officially Xerox
000001 SuperLAN-2U
000002 BBN (was internal usage only, no longer used)
000003 XEROX CORPORATION
000004 XEROX CORPORATION
000005 XEROX CORPORATION
000006 XEROX CORPORATION
000007 XEROX CORPORATION
000008 XEROX CORPORATION
000009 powerpipes?
#include <stdio.h> // for printf
#include <math.h> // for testing only, not used by cordic
#include "cordic-32bit.h" // for actual cordic algo
//Print out sin(x) vs fp CORDIC sin(x)
int main(int argc, char **argv)
{
float p;
// sin_int, cos_in;
@x42
x42 / peak_calc.cc
Last active September 24, 2021 16:20
// -- Linux / Intel --
// g++ -o peak_calc peak_calc.cc -Wall -mavx -lm -O3 -fopt-info && ./peak_calc
// g++ -o peak_calc peak_calc.cc -Wall -msse2 -lm -O3 -fopt-info && ./peak_calc
//
// -- Linux / ARM --
// g++ -o peak_calc peak_calc.cc -Wall -lm -O3 && ./peak_calc
// g++ -o peak_calc peak_calc.cc -Wall -mfpu=neon-vfpv4 -lm -O3 && ./peak_calc
//
// -- macOS --
// g++ -o peak_calc peak_calc.cc -Wall -lm -O3 -framework Accelerate

UNIX famously uses fork+exec to create processes, a simple API that is nevertheless quite tricky to use correctly and that comes with a bunch of problems. The alternative, spawn, as used by VMS, Windows NT and recently POSIX, fixes many of these issues but it overly complex and makes it hard to add new features.

prepare() is a proposed API to simplify process creation. When calling prepare(), the current thread enters “preparation state.” That means, a nascent process is created and the current thread is moved to the context of this process, but without changing memory maps (this is similar to how vfork() works). Inside the nascent process, you can configure the environment as desired and then call prep_execve() to execute a new program. On success, prep_execve() leaves preparation state, moving the current thread back to the parent's process context and returns (!) the pid of the now grownup child. You can also use prep_exit() to abort the child without executing a new process, it similarly returns the pid