Skip to content

Instantly share code, notes, and snippets.

@a3f
a3f / bootchooser
Created December 20, 2023 17:54
Simple Bootchooser + Bootloader Spec configuration with overlays
# cat /env/nv/bootchooser.system1.boot
mmc0.root-a
# cat /env/nv/bootchooser.system2.boot
mmc0.root-b
#!/bin/bash
set -e
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
echo "USAGE: $0 kernel-recipe [defconfig path]"
exit 1
fi
recipe=$1
#!/bin/bash
add=1
while getopts "dur" o; do
case "${o}" in
d|u|r)
add=0
;;
*)
@a3f
a3f / sndrv-interposer.c
Created July 5, 2021 16:59
Poor man's strace for SNDRV_PCM_IOCTL_SYNC_PTR and brethern
#define _GNU_SOURCE
#include <sound/asound.h>
#include <linux/ioctl.h>
#include <stdio.h>
#include <dlfcn.h>
#define report(...) fprintf(stderr, __VA_ARGS__)
static void decode_pcm_state(snd_pcm_state_t state)
{
@a3f
a3f / .twitter
Last active February 8, 2018 16:57
[API]
access_token=ADD_YOUR_TOKEN_HERE
access_token_secret=ADD_YOUR_TOKEN_HERE
api_key=ADD_YOUR_KEY_HERE
api_secret=ADD_YOUR_KEY_HERE
[SEARCH]
lastid=
@a3f
a3f / gist:d2249665e35cfc51e5ebf60534c053e6
Created July 23, 2017 05:37
Building mipsel-elf-gcc on macOS
export PREFIX=/opt/cross/gcc-mips
export PATH=${PREFIX}/bin:${PATH}
../binutils-2.28/configure --target=mipsel-elf --prefix=$PREFIX
../gcc-7.1.0/configure --target=mipsel-elf --prefix=$PREFIX --without-headers --with-gnu-as --with-gnu-ld --disable-shared --enable-languages=c --disable-libssp
@a3f
a3f / fslurp.c
Last active September 25, 2018 15:14
Slurp file into buffer with C stdio
long fslurp(char **buf, long *len, FILE *fp)
{
size_t new_len;
long size, start = ftell(fp);
if (start == -1 || fseek(fp, 0, SEEK_END) == -1)
return -1;
if ((size = ftell(fp)) == -1)
return -1;
@a3f
a3f / cancel.c
Created March 18, 2017 18:11
Possible pthreads race bug on macOS Sierra
/*
for i in `seq 100000`; do ./a.out $i ; done && echo ' All is well!'
*/
#include <assert.h>
#include <unistd.h>
#include <stdio.h>
#include <pthread.h>
void *interp(void *param) {
(void)param;
⚡ W=$(shuf -n1 /usr/share/dict/words) perl -ne'print$s=$ENV{W}=~s/[^.$_$s]/_/gri,"\n?"'
@a3f
a3f / game-of-life.pl
Last active January 5, 2017 15:20
Transliteration of life←{ ↑1 ⍵∨.∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵ } from APL to Perl
#!/usr/bin/perl
my $HZ = 100;
##################################
use Time::HiRes qw(sleep);
use PDL;
use PDL::Matrix;
use strict;
use warnings;