Skip to content

Instantly share code, notes, and snippets.

View submachine's full-sized avatar

Arjun Shankar submachine

  • Brno, Czech Republic
View GitHub Profile
@submachine
submachine / gen_rand_dag.c
Created October 9, 2012 00:37
A quick-n-dirty random DAG generator
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* http://stackoverflow.com/q/12790337/274261 */
/* Generates random DAGs. The key is to 'rank' the nodes, and
only draw edges from lower ranked nodes to higher ranked ones. */
/* Nodes/Rank: How 'fat' the DAG should be. */
@submachine
submachine / omp_atomic_capture_example.c
Created September 18, 2012 09:34
An atomic 'fetch and add' using OpenMP directives
/* Compiling with `gcc -fopenmp -m32 -O2 -S' produces:
movl $1, %eax
lock xaddl %eax, j
movl %eax, i
ret
*/
int i, j;
void foo (void)
@submachine
submachine / xrenderstring.c
Created July 27, 2012 10:50
A program that takes: font, string, and renders accordingly using Xlib. Almost a verbatim copy of the one at: http://www.lemoda.net/c/xlib-text-box/index.html
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* The window which contains the text. */
struct
{
int width;
@submachine
submachine / memhash.c
Created July 6, 2012 23:34
A toy x86_64 pointer-hash benchmark to go with the StackOverflow answer at: http://stackoverflow.com/a/11364619/274261
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#define HASH_BITS 10
#define BUCKETS (1 << HASH_BITS)
/* A half-avalanche 4 byte integer hash function, as described at:
http://burtleburtle.net/bob/hash/integer.html */