Skip to content

Instantly share code, notes, and snippets.

View mlabbe's full-sized avatar

Michael Labbe mlabbe

View GitHub Profile
@mlabbe
mlabbe / play_random_album.pl
Created July 3, 2025 17:22
play random album
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use File::Find;
use List::Util 'shuffle';
# config
my $music_dir = "$ENV{HOME}/Music/mp3s";
my $num_albums = 1;
@mlabbe
mlabbe / update_packages.sh
Created June 29, 2025 14:53
Update Emacs packages on the command line
#!/bin/sh
emacs --batch -l ~/.emacs \
--eval="(progn (require 'package) \
(package-initialize) \
(package-refresh-contents) \
(mapc (lambda (pkg)
(let* ((new (cadr (assq pkg package-archive-contents)))
(installed (cadr (assq pkg package-alist))))
(when (and new installed
#import <Cocoa/Cocoa.h>
#import <ApplicationServices/ApplicationServices.h>
CGEventTimestamp lastTimestamp = 0;
CGEventRef eventTapCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {
if (type == kCGEventMouseMoved) {
CGPoint location = CGEventGetLocation(event);
NSLog(@"Mouse moved to: x = %.2f, y = %.2f", location.x, location.y);
CGEventTimestamp currentTimestamp = CGEventGetTimestamp(event);
@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