Skip to content

Instantly share code, notes, and snippets.

View mlabbe's full-sized avatar

Michael Labbe mlabbe

View GitHub Profile
@mlabbe
mlabbe / build.sh
Last active March 6, 2020 04:54
Override a function at link time by weakening it with objcopy
#!/bin/sh -x
rm -f *.o weak
CC=clang-9
LD=$CC
CFLAGS="-fno-inline-functions -O0"
$CC -c weak.c -o weak.o $CFLAGS
$CC -c weak_b.c -o weak_b.o $CFLAGS
@mlabbe
mlabbe / build.sh
Last active March 19, 2024 10:34
Use clang linker --wrap to wrap a function in the same compilation unit
#!/bin/sh -x
CC=clang-9
rm -f *.o wrap nowrap
# build without wrapping
$CC -c wrap.c -o wrap.o
$CC -c wrap_b.c -o wrap_b.o
$CC wrap.o wrap_b.o -o nowrap
@mlabbe
mlabbe / ftg_core.h
Created December 7, 2019 07:38
Parse Terminfo binary files without dependency libraries
/* ftg_core.h - v0.5 - Frogtoss Toolbox. Public domain-like license below.
ftg libraries are copyright (C) 2015 Frogtoss Games, Inc.
http://github.com/mlabbe/ftg_toolbox
ftg header files are single file header files intended to be useful
in C/C++. ftg_core contains generally useful functions
Special thanks to STB for the inspiration.
@mlabbe
mlabbe / new.lua
Last active August 23, 2019 19:51
Pico-8 starting point
dev = true
ent_list = {}
types = {}
cam={0,0} -- world top-left
--
-- helpers
--
function get_player(n)
@mlabbe
mlabbe / secgroup.sh
Created June 23, 2019 23:11
Bash script to set an AWS security group to use your current IP address, exclusively. Also works over ipv6 gateways (like your phone tether).
#!/bin/bash
#
# Roaming security group by Michael Labbe
# @frogtoss
#
# security group id
GROUP_ID="sg-xxx"
@mlabbe
mlabbe / clang-format.el
Last active June 17, 2019 20:57
Run clang-format only when projects have a .clang-format in their root, while deferring the load of all packages with use-package
(use-package cc-mode
:defer t
:init
(add-hook 'before-save-hook #'clang-format-buffer-smart)
:config
(progn
(defun clang-format-buffer-smart()
"Reformat buffer only if .clang-format exists in the projectile root."
(when (file-exists-p (expand-file-name ".clang-format" (projectile-project-root)))
(clang-format-buffer)))
@mlabbe
mlabbe / calc.rs
Created March 12, 2019 04:44
A simple calculator in rust (my first rust program)
/*
simple rust calculator
add_op := '+' | '-'
mul_op := '*' | '/'
digits := {'+' | '-'} [0..9] {[0..9]}
expr := term {add_op term}
term := factor {mul_op factor}
factor := digits | '(' expr ')'
@mlabbe
mlabbe / zt.c
Created February 25, 2019 23:40
zero tuple
typedef union {
struct tuple_s { char a; short b; long long c; }tuple;
uint64_t _all[sizeof(struct tuple_s)/sizeof(uint64_t)];
}zero_tuple_u;
int main() {
zero_tuple_u t = {._all = {0}};
}
@mlabbe
mlabbe / quarantine_node.sh
Created September 15, 2018 15:22
Install Quarantined NodeJS to avoid systemwide pollution
export INSTALLDIR=$HOME/dev/node/local # or wherever
mkdir -p $INSTALLDIR
# Put these lines in your .bashrc
export PATH=$INSTALLDIR/bin:$PATH
export MANPATH=$INSTALLDIR/share/man
git clone https://github.com/nodejs/node
cd node
@mlabbe
mlabbe / calc.c
Last active July 29, 2023 17:34
A simple calculator written as an ll1 recursive descent parser
/*
simple calculator implemented via recursive descent
add_op := + | -
mul_op := * | /
digits := {+|-} [0..9] {[0..9]}
expr := term {add_op term}
term := factor {mul_op factor}