Skip to content

Instantly share code, notes, and snippets.

View imaami's full-sized avatar
🐺
C/C++/Linux ░▒▓▉▊▋▌▍▎▏

Juuso Alasuutari imaami

🐺
C/C++/Linux ░▒▓▉▊▋▌▍▎▏
  • Finland
View GitHub Profile
@imaami
imaami / vsplit.sh
Created February 28, 2025 17:30
Generate a list of GitHub caching keys from a semantic version
#!/usr/bin/env bash
vsplit() {
local k="$1" r
while [[ "$k" != "$r" ]]; do
echo "$k"; r="$k"
k="${k%?${k##*[0-9][.+-]}}"
done
}
@imaami
imaami / dbs26.c
Last active February 3, 2025 20:08
Generate all 67108864 64-bit binary De Bruijn sequences in 3 seconds
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/**
* @file dbs26.c
* @brief Generate all 67108864 unique binary De Bruijn sequences
* with subsequence length 6, ordered by value.
*
* Compiling with MSVC on Windows:
* cl /TC /std:clatest /experimental:c11atomics /O2 /Oi /GL /GF /Zo- /favor:AMD64 /arch:AVX2 dbs26.c /Fe: dbs26.exe /MT
*
* @author Juuso Alasuutari
@imaami
imaami / README.md
Last active December 6, 2024 18:23
Sculpt hallucinated lyrics into neon echoes

wheeze.py

wheeze.py is a tool to help generate lyrics for music, but in a music-first way. It can be thought of as the reverse of the typical LLM-assisted approach.

(The first two letters come from OpenAI's whisper. I haven't invented a post-hoc rationale for the rest of the name yet.)

@imaami
imaami / b24_expand.c
Last active September 13, 2024 18:39
Expand all overlapping 4-bit subsequences of a circular 16-bit sequence
static uint64_t
b24_expand (uint16_t seq)
{
#define seq_prep(x) 0, (uint32_t)((x) << 12U | \
(x) >> 4U) << 16U | (x)
__m128i k = _mm_shuffle_epi8(
_mm_set_epi64x(seq_prep(seq)),
_mm_set_epi64x(UINT64_C(0x0303030301010101), \
UINT64_C(0x0202020200000000)));
#undef seq_prep
@imaami
imaami / shuffle_u8x16.c
Last active September 15, 2024 11:25
Expand subsequences
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __aarch64__
#include <arm_neon.h>
@imaami
imaami / popcnt.h
Last active October 21, 2024 18:34
Generic popcount
/** @file popcnt.h
*/
#ifndef POPCNT_H_
#define POPCNT_H_
#include <limits.h>
#include <stdint.h>
#undef define_popcnt
#undef popcnt16_impl
@imaami
imaami / uwu.c
Last active September 10, 2024 19:30
uWu
#include <stdio.h>
#include <math.h>
int main(void)
{
typeof(sizeof M_E)
t=pow ( M_E,
((typeof(sizeof M_E))01 << ' ')
/(typeof( M_E))0xf0f04ef)
/ M_PI;
@imaami
imaami / fizzbuzz_by_claude_35_sonnet.c
Created September 9, 2024 16:36
FizzBuzz Enterprise Edition by claude-3.5-sonnet
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_FIZZBUZZ_LENGTH 8
#define MAX_NUMBER_LENGTH 10
typedef struct {
int (*evaluate)(int);
char *(*transform)(void);
@imaami
imaami / b24.c
Last active October 1, 2024 18:40
B(2, 4)
/**
* @file b24.c
*
* Compiling with MSVC 19.41 or later:
*
* cl.exe /TC /std:clatest /O2 /Oi /GL /GF /Zo- /favor:AMD64 /arch:AVX2 b24.c /Fe: b24.exe /MD
*/
#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
@imaami
imaami / Makefile.gnu23
Created July 9, 2024 12:48
Experimenting with compiler introspection in GNU Make
.PHONY: default gnu23 gnu23.mk
default:| gnu23; $(info $(CC) -std=$(gnu23))
gnu23:| gnu23.mk; $(eval include gnu23.mk)
gnu23.mk: gnu23.h; @$(CC) -E -xc -P $< >$@
gnu23.h: $(lastword $(MAKEFILE_LIST)); $(call cstd,$@) @:
override cstd =$(file >$1,$(.cstd))
override .cstd =$(call \
P,#ifdef __clang_major__) $(call \
L,#if __clang_major__ > 17) $(call \
L,override gnu23 := gnu23) $(call \