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
Created December 11, 2020 23:08
MacOS M1 cross compile and build a fat binary with aarch64/arm64 and x86_64/amd64
#!/bin/bash
clang hello.c -target arm64-apple-darwin20.1.0 -o hello.arm64
echo -n "hello.arm64 is architecture " && lipo -archs ./hello.arm64
clang hello.c -target x86_64-apple-darwin-macho -o hello.x86_64
echo -n "hello.x86_64 is architecture " && lipo -archs ./hello.x86_64
lipo hello.arm64 hello.x86_64 -create -output hello
echo -n "final output binary has archs " && lipo -archs ./hello
@mlabbe
mlabbe / ifdef-disable.el
Created December 3, 2020 17:31
yasnippet disable a region with #if 0
# -*- mode: snippet -*-
# name: ifdef-disable
# key: ifdef-disable
# binding: M-#
# expand-env: ((yas-wrap-around-region nil))
# --
#if 0
`yas-selected-text`#else
$0
#endif
@mlabbe
mlabbe / i3_config
Created April 30, 2020 18:12
Run Emacsclient on i3wm scratchpad workspace
# launch scratchpad frame in existing emacs daemon
exec --no-startup-id /usr/local/bin/pad.sh
# when scratchpad frame is launched, move it to the scratchpad workspace
for_window [title="_emacs scratchpad_" class="Emacs"] move scratchpad
@mlabbe
mlabbe / build.sh
Last active March 6, 2020 04:47
Redefine a symbol in a compiled elf object file
#!/bin/sh -x
rm -f *.o redefine
CC=clang-9
LD=$CC
CFLAGS="-fno-inline-functions -O0"
$CC -c redefine.c -o redefine.o $CFLAGS
$CC -c redefine_b.c -o redefine_b.o $CFLAGS
@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 May 18, 2024 07:10
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)))