Skip to content

Instantly share code, notes, and snippets.

View tekknolagi's full-sized avatar
🚴

Max Bernstein tekknolagi

🚴
View GitHub Profile
@tekknolagi
tekknolagi / run.py
Last active February 13, 2024 02:35
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com)
import shlex
import subprocess
import sys
import textwrap
def with_pty(command):
@tekknolagi
tekknolagi / hist.sh
Last active February 10, 2023 17:17
#!/bin/sh
# Likely originally by Carl Shapiro
sort |
uniq -c |
sort -n |
sed 's/^ *//' |
awk 'BEGIN { OFS="\t"} { sum += $1; print sum, $1, substr($0, 1 + index($0, " ")) }' |
sort -n -r |
awk 'BEGIN { IFS=OFS="\t"; print "cum", "pct", "freq" }$1 > max { max = $1 }{ print int($1/max*100), int($2/max*100), $2, $3 }'
@tekknolagi
tekknolagi / enum_bitmask.hpp
Created May 3, 2022 06:50 — forked from StrikerX3/enum_bitmask.hpp
Type-safe enum bitmasks
/*
Type-safe enum class bitmasks.
Based on work by Andre Haupt from his blog at
http://blog.bitwigglers.org/using-enum-classes-as-type-safe-bitmasks/
To enable enum classes to be used as bitmasks, use the ENABLE_BITMASK_OPERATORS
macro:
enum class MyBitmask {
None = 0b0000,
One = 0b0001,
Two = 0b0010,
// Need Clang 13 for __attribute__((musttail))
// clang++-13 -std=c++11 -g -O0 stencil.cpp
#include <cassert>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <vector>
#include <sys/mman.h>
(() => {
////////////////////////////////////////////////////////////////////////////////
// Dragging
const dragTarget = document.getElementById('dragTarget');
const uploadFiles = document.getElementById('uploadFiles');
const loadExample = document.getElementById('loadExample');
let dragging = 0;
let filesInput;
@tekknolagi
tekknolagi / stack_machine.cpp
Created February 2, 2021 04:11 — forked from glampert/stack_machine.cpp
1-register stack caching test for stack-based interpreters.
//
// Simple stack-based virtual machine tests.
//
// I use two slightly different strategies to manage the
// interpreter stack: First is using the "naive" approach
// of keeping a stack pointer that is bumped/decremented
// for every instruction that has stack operands. The second
// approach uses a "stack cache" register to cache the
// Top-of-Stack (TOS) value.
//
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// TODO(max): Consider writing this in Rust or Nim for some extra reader
// appeal.
typedef enum {
kInt,
@tekknolagi
tekknolagi / aoc8-compiler.py
Created December 13, 2020 22:36
Advent of Code Handheld Halting Compiler
import sys
def compile(prog):
result = (
"#include <stdbool.h>\n"
"#include <stdio.h>\n"
"#include <string.h>\n"
"int execute() {\n"
"int acc = 0;\n"
@tekknolagi
tekknolagi / Makefile
Last active March 13, 2024 22:46 — forked from pervognsen/asm_x64.c
x86-64 assembler in C
all:
gcc -Wall -Wextra -pedantic -g asm_x64.c -o asm_x64
@tekknolagi
tekknolagi / gartersnake.py
Last active July 7, 2022 23:09
A small Python to C compiler...
import ast
import sys
import json
NoSemicolon = True
class CompileError(Exception):
pass