Navigation Menu

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 / stringy_check.c
Last active January 12, 2024 13:43
Check for stringy primes
/* SPDX-License-Identifier: GPL-2.0-or-later */
/**
* @file stringy_check.c
* @author Juuso Alasuutari
*
* @brief Parse the raw content bytes of text strings as if the strings were
* arbitrarily large integers, and check if the result is a different
* prime number in both the big- and little-endian byte orders.
*
* I call the group of primes generated by this method "stringy primes"; run
@imaami
imaami / bashplainer.sh
Last active December 22, 2023 11:40
Document your bash scripts or Meth Santa visits you in your sleep
#!/usr/bin/env bash
#
# IMPORTANT: The HTTP authorization header must be found
# in ~/.openai in full, not just the API key.
#
# Usage: ./bashplainer.sh /path/to/file.sh
#
# Requirements: dos2unix, jq, curl
#
@imaami
imaami / documentarist2.sh
Created December 20, 2023 19:49
Let GPT describe how your code sucks.
#!/usr/bin/env bash
#
# IMPORTANT: The HTTP authorization header must be found
# in ~/.openai in full, not just the API key.
#
# Usage: ./documentarist.sh [options] /path/to/file.c
#
# Requirements: dos2unix, cpp, clang-format, jq, curl
#
@imaami
imaami / etc_hosts_dig.sh
Created December 18, 2023 23:32
Cisco Umbrella is a perfect system without flaws
#!/usr/bin/env bash
#
# Usage (_only_ if you really know what you're doing):
# etc_hosts_dig.sh >> /etc/hosts
# expand this list as needed
declare -a hosts_list=(
api.openai.com
auth0.openai.com
cdn.openai.com
@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 / 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'
#
#!/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 / transaction.c
Created April 8, 2023 12:45
Atomic transaction lock in C w/ compile-time magic
#include <stdatomic.h>
#include <stdbool.h>
#include <stdlib.h>
#define TRANSACTION(name, ptr, lock, expect, desire) \
struct { \
union { \
atomic_ulong *state; \
struct { \
char lock_bit[(lock)]; \
@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;