Skip to content

Instantly share code, notes, and snippets.

View apaz-cli's full-sized avatar
🎶
Hiding in your wifi

apaz apaz-cli

🎶
Hiding in your wifi
View GitHub Profile
ceqexpr <- rule:next
(op:(EQ / PLEQ / MINEQ / MULEQ / DIVEQ / MODEQ / ANDEQ / OREQ / XOREQ / BNEQ / BSREQ / BSLEQ)
t:next
{
if (op->kind == kind(EQ)) rule=repr(node(EQ, rule, t), op);
else if (op->kind == kind(PLEQ)) rule=repr(node(EQ, rule, binop(repr(leaf(PLUS), op), rule, t)), op);
else if (op->kind == kind(MINEQ)) rule=repr(node(EQ, rule, binop(repr(leaf(MINUS), op), rule, t)), op);
else if (op->kind == kind(MULEQ)) rule=repr(node(EQ, rule, binop(repr(leaf(MUL), op), rule, t)), op);
else if (op->kind == kind(DIVEQ)) rule=repr(node(EQ, rule, binop(repr(leaf(DIV), op), rule, t)), op);
else if (op->kind == kind(MODEQ)) rule=repr(node(EQ, rule, binop(repr(leaf(MOD), op), rule, t)), op);
@apaz-cli
apaz-cli / findpython.sh
Created March 29, 2023 05:55
Find python version
#!/bin/sh
# Ask python and python3 for their versions, if present.
if test $(which python); then
PYV=$(python -c "import platform;print(platform.python_version())");
fi
if test $(which python3); then
PY3V=$(python3 -c "import platform;print(platform.python_version())");
fi
@apaz-cli
apaz-cli / sr.py
Created February 26, 2023 21:08
Search and Replace script
# USAGE:
# py sr.py <target> <output> (<search> <replace>)*
import sys
def fopen(fname):
with open(fname, 'r') as file:
return file.read()
@apaz-cli
apaz-cli / pl0_parser.c
Created February 26, 2023 21:07
Example parser using GNU label as value extensions
#ifndef PL0_PARSER_INCLUDE
#define PL0_PARSER_INCLUDE
#include <stdio.h>
#include <stdlib.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu-label-as-value"
/***********/
/* Grammar */
@apaz-cli
apaz-cli / tui.h
Last active August 25, 2023 04:01
Tui API rough draft
struct Event {
bool handled;
enum {END, RESIZE, MOUSE, KEY} kind;
union {
struct ResizeEvent {
uint16_t new_width, new_height;
};
struct MouseEvent {
uint16_t mouse_x, mouse_y;
@apaz-cli
apaz-cli / daisho_parse_fntype.c
Last active August 22, 2022 02:54
An example of the code generated by pgen.
/*
fntype <- FNTYPE
LT
argtypes:{ret=list(ARGLIST)}
( t:type {add(argtypes, t)})?
(COMMA t:type {add(argtypes, t)})*
{if (!argtypes->num_children) add(argtypes, leaf(VOIDTYPE))}
(arrow:ARROW rettype:type)?
GT
{rule=node(FNTYPE, argtypes, rettype!=SUCC ? rettype : leaf(VOIDTYPE))}
@apaz-cli
apaz-cli / asan_err.c
Last active August 22, 2022 20:57
Asan error
#include <stdio.h>
#include <signal.h>
#include <setjmp.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <pthread.h>
#include <errno.h>
#include <sys/mman.h>
@apaz-cli
apaz-cli / Kaboom.c
Created August 5, 2022 19:02
The Halting Problem
/*
* The Halting Problem:
* Does there exist an algorithm which can determine if any complete program
* halts? Complete means that all information about the program must be known
* beforehand.
*
*
* The definition in computability theory for "Algorithm" is:
* "A finite list of instructions which when carried out must
* always terminate."
@apaz-cli
apaz-cli / bitmask_allocator.h
Created July 5, 2022 22:17
Efficient fixed size allocator
#include <stdio.h>
#include <stdint.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#define ALLOC_SIZE 128 // The size of the object to allocate
#define PAGE_SIZE 4096 // OS page size (almost always 4096)
#define NUM_PAGES 20 // The number of OS pages to reserve.
#define ARENA_SIZE (PAGE_SIZE * NUM_PAGES) // The amout of memory to reserve.
#include <limits.h>
#include <stdio.h>
#define EN "\x1b[36m"
#define BX "\x1b[31m"
#define RS "\x1b[0m"
#define LT "\x1b[33m"
int main(void) {
puts(BX "======================== ASCII TABLE ========================");
for (char i = 32;; i++) {