Skip to content

Instantly share code, notes, and snippets.

@deepcube
deepcube / offsets.awk
Last active December 17, 2015 09:09
Given a file, print each word followed by byte offsets at which it is found. offsets.c and offsets.bash should be interchangeable. ./offsets < file | awk -f offsets.awk | sort | column -t
# offsets.awk
#
# given a list of word offset pairs, accumulate offsets and print
# word [offset,...] pairs
# use with offsets.c
# no good way to shebang awk, so just do awk -f manually
{
a[$1] = a[$1] (a[$1] ? "," : "") $2;
}
@deepcube
deepcube / czmq_connect_die.c
Created April 19, 2013 20:32
Rewrite of https://gist.github.com/deepcube/5417288 in czmq. To run download all files in a directory and run: sh czmq_disconnect_test.sh
#include <czmq.h>
#include <stdio.h>
#include <stdlib.h>
#include <zmq.h>
#define zcheck_err(eval, condition, fmt, args...) \
((void)({ \
errno = 0; \
if (!(condition)) { \
fprintf(stderr, "%s: " fmt "%s%s\n", prog_name, ##args, errno ? ": " : "", errno ? zmq_strerror(errno) : ""); \
@deepcube
deepcube / many.c
Last active December 16, 2015 10:49
Continually create and destroy contexts and sockets to check for memory leaks. None found. To run download both files into a directory and run: sh many_test.sh
#include <czmq.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <zmq.h>
#define zcheck_err(eval, condition, fmt, args...) \
((void)({ \
errno = 0; \
if (!(condition)) { \
@deepcube
deepcube / connect_die.c
Last active December 16, 2015 09:59
Test whether ZMQ_ROUTER sockets grow as peers connect and disconnect. It looks like they don't. To run, download all three files into the same directory and run: sh disconnect_test.sh
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zmq.h>
#define zcheck_err(eval, condition, fmt, args...) \
((void)({ \
errno = 0; \
if (!(condition)) { \