Skip to content

Instantly share code, notes, and snippets.

View kulp's full-sized avatar
💬
ceci n'est pas un statut

Darren Kulp kulp

💬
ceci n'est pas un statut
View GitHub Profile
@kulp
kulp / statictree_statictree.h
Created April 7, 2011 18:32
provides macros for compactly representing tree-like structures at compile-time
/**
* @file
* Provides macros for compactly representing tree-like structures at compile-
* time.
*
* Must be compiled as C99 code to work correctly. With GCC, use -std=c99 or
* a superset thereof.
*
* Currently, traversal must be done manually. Soon, functions will exist to
* traverse the tree without understanding its internal structure.
@kulp
kulp / kv_int.h
Created April 7, 2011 18:20
A lightweight integer-keyed key-value store
/**
* @file
* Provides a lightweight integer-keyed key-value store.
*
* The key must be an integral type (default @c int), but can be any integral
* type if @c KV_KEY_TYPE is defined before @c #include'ing this file.
*/
#ifndef KV_INT_H_
#define KV_INT_H_
@kulp
kulp / synchronize_c.h
Created October 6, 2010 17:40
Adds Java-like function-granular locking
// Adds Java-like "synchronize" to functions.
#if SYNCHRONIZE_ENABLE
#include <pthread.h>
#define SYNCHRONIZED(Ret,Func,Params,Args) \
static Ret _synchronized_##Func Params; \
Ret Func Params { \
Ret _result; \
static pthread_mutex_t _lock_for_##Func = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; \
@kulp
kulp / findcol.pl
Created July 19, 2010 19:24
findcol.pl
#!/usr/bin/env perl
use strict;
use List::Util qw(max);
# so we don't have to bring in non-code List::MoreUtils
sub all (&@)
{
my ($block, $a) = @_;
return @$a == grep { $block->() } @$a;
@kulp
kulp / findfield.pl
Created July 19, 2010 19:24
findfield.pl
#!/usr/bin/env perl
use strict;
my @n = sort { $a <=> $b } @ARGV;
my %n = map { $_ => 1 } @n;
my $line = <STDIN>;
for my $i (0 .. $n[-1]) {
print 0 + pos $line, " " if $n{$i};
$line =~ /\G\s+X+/gc;
}
@kulp
kulp / svg2cfdg.pl
Created April 14, 2010 03:19
Converts SVG to Context-Free
#!/usr/bin/env perl
use strict;
use List::MoreUtils qw(zip);
use File::Basename qw(basename);
use XML::Simple;
use XXX;
my $num = qr/[0-9.]+/;
my $cmd = qr/[MZLHVCSQTA]/i;
@kulp
kulp / tree_macro.pl
Created March 30, 2010 22:54
Generates CPP macros for mapping arbitrary integer sets to small integer sets
#!/usr/bin/env perl
use strict;
use List::Util qw(max);
my $name = "b";
# for each significant bit position, where the sequence through the bit
# positions is chosen such that each bit chosen divides the remaining
# search space as nearly evenly as possible, construct an array that
# looks like this:
@kulp
kulp / xml2nsisxml.pl
Created March 30, 2010 18:49
Creates nsisXML scripts from XML files
#!/usr/bin/env perl
use strict;
use XML::SAX::ParserFactory;
our $p = "nsisXML::";
our $f = "/NOUNLOAD";
our $i = " " x 2;
$XML::SAX::ParserPackage = "XML::SAX::Expat";
#!/usr/bin/env perl
use strict;
use List::Util qw(max);
my $name = "b";
# for each significant bit position, where the sequence through the bit
# positions is chosen such that each bit chosen divides the remaining
# search space as nearly evenly as possible, construct an array that
# looks like this:
FAKELIBS += libfoo libbar
CLEANFILES += $(FAKELIBS:=.x)
libfoo_FAKESYMS = foosym1 foosym2
libbar_FAKESYMS = barsym1 barsym2
# Rules to create fake libraries that can stand in during link time only for
# real libraries that are not yet available.
define FAKE_LIBRARY_template
$(1).x:
echo $(2) | sed 's/\($$$$\| \)/ = 0;^M/g' > $$@