Skip to content

Instantly share code, notes, and snippets.

@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;
}
@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 / 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 / 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 / play
Created July 13, 2014 00:56
iTunes stopped working again. I wrote a simple music queue/player.
#!/usr/bin/env sh
TIMEOUT=0
while true; do
AUDIO_FILE=$(redis-cli BLPOP "$MUSIC_QUEUE" $TIMEOUT | grep --max-count=1 '^/')
afplay "$AUDIO_FILE"
done
module RParse
class Parser
def initialize(&block)
@block = block
end
def char(c)
case @buffer[0]
when c
* * * * * /usr/bin/curl --user-agent "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16" --location http://www.google.com >/dev/null 2>&1
@dgalling
dgalling / AndroidManifest.xml
Created August 16, 2012 03:53
Correct Android Manifest
<manifest ...>
<permission android:name="com.example.project.EXAMPLE_PERMISSION" android:protectionLevel="signature"/>
<uses-permission android:name="com.example.project.EXAMPLE_PERMISSION"/>
<application ...>
<provider android:name=".ExampleProvider" android:grantUriPermissions="false" android:permission="com.example.project.EXAMPLE_PERMISSION"/>
</application>
</manifest>
default rel
bits 64
; stuff we need to export to C
global _fiber_new
global _fiber_yield
global _fiber_start
global _fiber_resume
global _main
LEADER='==>'
echo $LEADER 'Fetching vim from hg...'
hg clone https://vim.googlecode.com/hg/ vim
cd vim/src
echo $LEADER 'Configuring...'
./configure --enable-rubyinterp --enable-multibyte --enable-gui=no --disable-netbeans --with-compiledby=Ian\ Rahimi --enable-pythoninterp --disable-gtktest
echo $LEADER 'Building...'