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 / 99-xdm.rules
Last active December 18, 2023 23:15
Correctly defer xdm.service until /dev/dri/card0 exists.
# /etc/udev/rules.d/99-xdm.rules
# Create a dev-dri-card0.device unit for xdm.service to wait on.
SUBSYSTEM=="drm", KERNEL=="card0", TAG+="systemd"
@imaami
imaami / debruijn26.c
Last active April 2, 2024 00:00
Generate all 67108864 De Bruijn sequences B(2, 6)
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define force_inline __attribute__((always_inline)) inline
@imaami
imaami / quizgpt.sh
Created September 12, 2023 12:31
QuizGPT
#!/usr/bin/env bash
#
# IMPORTANT: The HTTP authorization header must be found
# in ~/.openai in full, not just the API key.
#
# Usage: ./quizgpt.sh <windowtitle> <expertrole>
#
# Example:
# ./quizgpt.sh 'Online C quiz' 'a C programmer'
#
@imaami
imaami / emanate_metaname.c
Last active March 1, 2024 21:26
Emanate metaname
/*
e e e e e
e m a n a t e m e t a n a m e
a a a a a
n n n n n
a a a a a
t t t t t
e e e e e
e m a n a t e m e t a n a m e
e e e e e
#!/usr/bin/env bash
word_max=9 # Exclude words longer than this
nphrases=3 # Generate this many passphrases
defwords=4 # Default number of words/phrase
pls() {
local -i n=${#1} r=$2
local s
printf -v s -- ' %s%*s%s\n' \
@imaami
imaami / metamap.c
Last active July 24, 2023 00:40
Type information-encoded flags in C
#include <stdio.h>
enum {
FOO = 1 << 0,
BAR = 1 << 1,
BYX = 1 << 2,
QUE = 1 << 3
};
#define maybe_signed(T, cond) __typeof__( \
@imaami
imaami / sizeofplusplus.c
Created July 21, 2023 00:10
Cursed sizeof.
#include <stdio.h>
#define sizeof(x) (!(#x[0]^0x27)?:sizeof(x))
#define q(x) printf("%-7s\t%zu\n", #x, x)
#define p(x) q(sizeof(x))
int main (void)
{
char s[7], c;
@imaami
imaami / cartoon.c
Created July 20, 2023 21:09
A cartoonish C program.
#include <stdio.h>
#define ___ putchar
#define __ sizeof
#define _ __func__
int main(
void
){___(*(_+((*_>>(__(__(_))>>
4))&(*_>>__(_)))));___(*(_+((*_>>(__(__(_))>>
2))&(*_>>__(_)))));___(*(_+((*_>>(__(__(_))>>
1))&(*_>>__(_)))));___(*(_+((*_>>(__(__(_))>>
@imaami
imaami / spooky_message.c
Last active July 20, 2023 21:02
A spooky message in perfectly legible C.
/*----------------------------*
| s p o o k y m e s s a g e |
*----------------------------*/
#include <stdio.h>
#include <string.h>
__typeof__(~
sizeof("{%s, n%s}\n")) main
( __typeof__(~*
"")eof__,
__typeof__(*
@imaami
imaami / tautology.cpp
Created July 20, 2023 20:51
A value that is both bool(true) and EXIT_SUCCESS.
#include <cstdio>
int main() {
constexpr auto tautology{1ull << 63};
if (tautology)
std::puts("raw value evaluates to true");
if (static_cast<bool>(tautology))
std::puts("bool conversion equals true");