Back to home


Hi! This is my place for stuff I always forget.

Create a printf wrapper

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

/* Attribute for functions with the same declaration as printf(3) so that we get
 * type checking on GCC-like compilers. */
#ifdef __GNUC__
        #define PRINTF_WRAPPER __attribute__ ((format (printf, 1, 2)))
        #define PRINTF_WRAPPER

PRINTF_WRAPPER void die(const char *format, ...)
        va_list args;
        va_start(args, format);  /* format is the last known argument */

        vfprintf(stderr, format, args);



Send code into a REPL

Start a REPL:

dtach -c socket-location command [args...]

Connect to that REPL in another terminal:

dtach -a socket-location

Send code into that repl:

dtach -p socket-location <code

Use within vi(1):

:'a,. w !dtach -p socket-location

The website for dtach is here.

Use colors in the terminal

See this StackOverflow answer and this reference (the latter doesn't include newer extensions, which might be a good thing if your goal is to be as portable as possible.)