Skip to content

Instantly share code, notes, and snippets.

@dgalling
dgalling / realpath
Created July 13, 2014 00:59
Why doesn't OS X have this?
#!/usr/bin/env zsh
#
FILEPATH="$1"
echo $(cd "$(dirname "$FILEPATH")"; pwd)/$(basename $FILEPATH)
@dgalling
dgalling / defer.h
Created November 7, 2014 19:44
Deferred free in C
typedef struct free_list_t {
void (*func)(void *);
void *arg;
struct free_list_t *next;
} FreeList;
void _defer(FreeList **f, void (*func)(void *), void *arg) {
if (arg == NULL) {
return;
}
@dgalling
dgalling / cache.c
Created June 18, 2018 17:00
djbdns cache.c
#include "alloc.h"
#include "byte.h"
#include "uint32.h"
#include "exit.h"
#include "tai.h"
#include "cache.h"
uint64 cache_motion = 0;
static char *x = 0;
@dgalling
dgalling / add.c
Created September 8, 2024 18:09
Simple C interop example in swift
int add(int a, int b) {
return a + b;
}