Skip to content

Instantly share code, notes, and snippets.

View mlabbe's full-sized avatar

Michael Labbe mlabbe

View GitHub Profile
@mlabbe
mlabbe / add-llvm.pl
Created September 22, 2024 16:13
add llvm repo to ubuntu / linux mint and symlink llvm binaries, making it the default compiler
#!/usr/bin/perl -w
use strict;
# update this whe n new versions of llvm come out
my $llvm_version = 19;
# mint has a file that lets you know the ubuntu upstream release version
sub get_dist_version_from_mint {
open my $fh, '<', '/etc/upstream-release/lsb-release' or die;
@mlabbe
mlabbe / sizeof.c
Created December 11, 2023 17:53
C Print sizeof all types
#include <stdio.h>
#include <stdint.h> // uintptr_t
#include <stddef.h> // size_t
// enable printing sizes as ints to avoid faliing on compilers that don't support %zu
#define SIZEOF(expr) (int)sizeof(expr)
#define PRINT_SIZEOF(expr) printf("sizeof(%-11s) = %1d\n", #expr, SIZEOF(expr))
@mlabbe
mlabbe / ftg_bitbuffer.h
Last active January 12, 2023 22:22
bitbuffer
/* ftg_bitbuffer - public domain library
no warranty implied; use at your own risk
Tightly pack values by bits into a stream of bytes.
For example, a 1-bit bool and a 32-bit integer are packed into 33
bits.
Bitbuffers are intended for small amounts of data, like a few
hundred network packets where size is important enough to remove
@mlabbe
mlabbe / remedybg-mode.el
Created August 17, 2022 03:13
remedybg emacs minor mode (not ready for primetime)
;;
;; remedybg minor mode
;;
;; 0.1 by Michael Labbe
;;
(setq remedybg-path "c:/remedydbg/remedybg.exe")
(defun remedybg-add-breakpoint-at-file()
(interactive)
@mlabbe
mlabbe / log.h
Created December 28, 2021 19:49
Barebones code for a structured logger in C
#pragma once
// config
#define LOG_USE_STDIO 1
#define LOG_USE_FILE 0
#define LOG_USE_STRUCTURED 1
#define LOG_LEVEL_TRACE 0
#define LOG_LEVEL_WARN 1
#define LOG_LEVEL_ERROR 2
@mlabbe
mlabbe / log2json.py
Created December 27, 2021 20:58
Process structured logs to JSON
#!/usr/bin/env python3
# parse log.h's structured format:
#
# - each line ends with sequence 0x20 0x1a 0x0a
# - must parse through possible ascii escape sequences
# - 0x1b (esc) until 'm'
# - structure starts with line containing 3 upcase alpha chars
# - message ends with 0x1a 0x1a 0x0a
# - each line after the first is 0x09
@mlabbe
mlabbe / windowsupdate.conf
Created May 12, 2021 13:05
Block windows update dns records with dnsmasq
# put in /etc/dnsmask.d and restart the daemon
# then run ipconfig /flushdns
#
# run at your own risk
address=/windowsupdate.microsoft.com/0.0.0.0
address=/update.microsoft.com/0.0.0.0
address=/windowsupdate.com/0.0.0.0
address=/test.stats.update.microsoft.com/0.0.0.0
address=/ntservicepack.microsoft.com/0.0.0.0
address=/download.microsoft.com/0.0.0.0
@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