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
#!/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");
@imaami
imaami / includeinclude.sh
Created July 20, 2023 20:45
#include <#include> /* because why not? */
#!/usr/bin/bash
printf '%s\n' "int main(void) { puts(strchr(__FILE__, '#') ?: __FILE__); }" > './#include'
printf '#include <%s>\n' 'stdio.h' 'string.h' '#include' | cc -I. -o./includeinclude -xc -
./includeinclude
static const char *const SOURCE=(const char[]){
#embed __FILE__
,0}+72;
#include <stdio.h>
int main() {
puts(SOURCE);
}
@imaami
imaami / main.sh
Last active July 20, 2023 20:30
main? main.
#!/usr/bin/bash
#; / / #;
#; / / #;
#; / / #;
#;/ / #;
#; / #;
#; / ; ; ; ; #;
#; / ####### #;
#;/ ## C ## #;
#; ;#####; #;
@imaami
imaami / dstr_fini_test.c
Created July 9, 2023 21:43
Testing optimization levels
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define stringify_(x) #x
#define stringify(x) stringify_(x)