Skip to content

Instantly share code, notes, and snippets.

View Prince781's full-sized avatar
⚙️
Compiling a compiler

Princeton Ferro Prince781

⚙️
Compiling a compiler
View GitHub Profile
@Prince781
Prince781 / limit_process.zsh
Created December 26, 2023 20:46
launch program with memory bounds
limit_process() {
if (( $# < 2 )); then
echo "Usage: $0 size command ..."
return 1
fi
size=$1
command=(${@:2})
# run the process, stop, and save the PID
@Prince781
Prince781 / c23_iterator.c
Last active June 14, 2023 07:41
mostly-typesafe iterator in C23
// ISO C23 iterator for a non-const container
// compile with -std=c2x (gcc 13+, clang 16+)
struct iterator_base {
void *collection;
union {
void *state;
unsigned long size;
};
unsigned long index;
@Prince781
Prince781 / async.c
Created March 17, 2021 00:35
asynchronous event-driven I/O
#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>
#include <poll.h>
@Prince781
Prince781 / mingw-glib2-spawn-fixes-PKGBUILD.patch
Created October 9, 2020 15:38
build glib2 on msys2 with g_spawn() fixes
diff --git a/mingw-w64-glib2/PKGBUILD b/mingw-w64-glib2/PKGBUILD
index 380874721..e20bc32df 100644
--- a/mingw-w64-glib2/PKGBUILD
+++ b/mingw-w64-glib2/PKGBUILD
@@ -23,7 +23,7 @@ makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
"${MINGW_PACKAGE_PREFIX}-meson"
"${MINGW_PACKAGE_PREFIX}-gtk-doc"
"${MINGW_PACKAGE_PREFIX}-python-setuptools")
-source=("https://download.gnome.org/sources/glib/${pkgver%.*}/glib-${pkgver}.tar.xz"
+source=("git+https://gitlab.gnome.org/Prince781/glib"
@Prince781
Prince781 / gspawn-win32.c
Last active July 19, 2020 10:44
rewriting g_spawn_sync()'s Win32 backend...
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <Windows.h>
#define return_val_if_fail(expr, val)\
do {\
if (!(expr))\
@Prince781
Prince781 / randvar.py
Created December 9, 2019 23:22
discrete random variable mini-library
import random
from functools import reduce
import numbers
from math import sqrt, floor, ceil
# RV1 + RV2 = new RV
# same idea for other arithmetic ops
class RV:
@Prince781
Prince781 / ptr-atmt.c
Created June 3, 2019 16:42
pointer attachment example
// clang -fopenmp ptr-atmt.c -o ptr-atmt
#include <omp.h>
#include <stdio.h>
#pragma omp declare target
double *ptr;
void work(int i)
{
// work on ptr[i]
@Prince781
Prince781 / settheory.py
Last active April 9, 2019 15:48
music set theory analysis
#!/bin/env python3
import argparse
import re
import math
def get_pitch_class(note):
try:
p = int(note)
return p
@Prince781
Prince781 / setup_software.sh
Last active May 8, 2021 04:05
setup software in custom directory
#!/bin/bash
# vim: tw=0
if [ -z $SOFTWARE ]; then
echo "SOFTWARE undefined"
exit 1
fi
mkdir -p $SOFTWARE
mkdir -p $SOFTWARE/usr/share/man
@Prince781
Prince781 / primes.c
Last active October 28, 2015 20:59
get prime factorization
/* primes.c
* prints prime factorization of number
* `make primes`
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static const char *supers[] = {
"\u2070",