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 / gnuc_typeof_unqual.c
Last active April 15, 2023 13:20
Backport of C23's typeof_unqual using GNU extensions
/* If you compile with clang and `-Weverything' you'll probably want
* to use `-Wno-gnu-statement-expression-from-macro-expansion', too.
*
* Plain C18 version:
* https://gist.github.com/imaami/92b38f45142f8a8390fefa2d972bc63d
*/
#define typeof_unqual(x) __typeof__(({ *(__typeof__(x) *)(void *)0; }))
int main(void)
{
@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 / str.c
Created December 25, 2022 13:09
clever string
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct str {
union {
char *ptr;
@imaami
imaami / uint_str_alias.c
Last active December 16, 2022 15:17
Print an unsigned integer's content bytes as a string.
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct U {
union {
unsigned long long i;
char s[sizeof(unsigned long long)];
};
@imaami
imaami / named_sem.hpp
Last active June 26, 2023 01:54
I Made a POSIX Semaphore Wrapper and I'm So Sorry
/**
* @brief I Made a POSIX Semaphore Wrapper and I'm So Sorry
*
* Compile with -std=c++20 or later. Usage:
*
* auto *sem = new named_sem<"/name", O_CREAT | O_RDWR, 0666, 0>();
* if (sem) {
* sem->post();
* delete sem;
* }
@imaami
imaami / git-configs.sh
Last active December 7, 2020 12:19
git configuration script
#!/bin/bash
set_git_configs()
{
git config --global pull.ff only
}
set_git_aliases()
{
local -A ALIAS name
@imaami
imaami / .Xresources
Created December 1, 2020 13:52
Xresources
Xcursor.size: 24
Xft.antialias: true
Xft.rgba: none
Xft.hinting: true
Xft.autohint: true
Xft.hintstyle: full
! black
URxvt*color0: #000000
URxvt*color8: #686868
@imaami
imaami / team
Created November 7, 2020 16:21
Fix dmenu_run auto-completing "team" -> "teams" instead of "steam"
#!/bin/false
#
# This file exists because i3 really sucks at starting dmenu_run.
#
# Very often when I type mod4+d followed by "steam" and an enter keypress
# the first letter gets dropped (I assume because dmenu_run hasn't captured
# the keyboard yet). What ends up happening is that dmenu_run sees "team"
# and automatically finds the closest match which happens to be "teams".
#
# I almost never fucking want to launch Microsoft Teams, but I launch the
@imaami
imaami / headless_install_cuda_in_wine.md
Created July 13, 2020 23:51
Installing CUDA Toolkit 10.2 in Wine without a GUI

Installing CUDA Toolkit 10.2 in Wine

Steps

  1. Set and export shell variables

    Use a helper variable for the prefix name:

MYPREFIX=cudatest

@imaami
imaami / headless_install_cmake_in_wine.md
Last active August 31, 2021 09:46
Installing CMake for Windows in Wine without a GUI

Installing CMake for Windows in Wine without a GUI

Steps

  1. Set and export shell variables

    These variables are for our convenience:

MYPREFIX=cmaketest