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 / 7segment.c
Created April 10, 2012 02:08
Simple seven-segment decoder
#include <stdio.h>
#define countof(X) (sizeof (X) / sizeof (X)[0])
int display7(FILE *stream, unsigned char digit)
{
const char digits[][7] = {
['-'] = " -",
['0'] = "-||-|| ",
@kulp
kulp / critbit.c
Created January 20, 2012 19:15
Define and search a critbit tree
#include "critbit.h"
const node nodes[] = {
// read indices inside out
// for example, L(R(L(L(ROOT)))) is the root's left child's left child's
// right child's left child.
[ ROOT ] = { 6, 0 },
[ R(ROOT) ] = { 64, 1 },
[ L(ROOT) ] = { 5, 0 },
[ R(L(ROOT)) ] = { 32, 1 },
@kulp
kulp / sb.pl
Created November 22, 2011 14:39
a daemon to respond to events from Sound Blaster Surround 5.1-like devices
#!/usr/bin/env perl
use strict;
use warnings;
use Device::USB;
my ($vendorid, $productid) = (0x041e, 0x30df);
my $usb = Device::USB->new;
my $dev = $usb->find_device($vendorid, $productid)
@kulp
kulp / README
Created November 8, 2011 15:31
A toy exception handling system for C
sauf is a lightweight exception handling system for C.
The original implementation idea came from an article in Dr.
Dobb's Journal : http://www.on-time.com/ddj0011.htm
Some implementation details were taken from the excc project :
http://adomas.org/excc/ . This project was almost sufficient to my
requirements, but it requires GCC (sauf aims to work with any C99-
compliant compiler) and does not support 'finally' blocks.
@kulp
kulp / reg2nsh.c
Created October 5, 2011 15:14
Convert .REG (exported registry files) into .NSH-style registry commands
/*
reg2nsh.c : Converts .REG (exported registry files) into .NSH-style
registry commands, for use with the NSIS ( http://nsis.sf.net/ ).
$Rev$
$Date$
Copyright (c) 2005 Darren Kulp under the terms of the MIT License
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@kulp
kulp / moveptr.c
Created October 5, 2011 15:04
Moves the mouse pointer between screens on an X11 display
/**
* @file
* @brief Moves the mouse pointer between screens on an X11 display.
*
* This program might be useful to you if you wish to switch between two X11
* screens without moving your hands from the keyboard. I configure bbkeys to
* map the otherwise-unused windows keys and right-click key to move to the left
* screen, move to the right screen, and toggle between screens, respectively.
*
* Run with zero to three arguments (additional arguments are ignored). The
@kulp
kulp / wolfeval.pl
Created September 27, 2011 17:40
simple command-line WolframAlpha numerical evaluator
#!/usr/bin/env perl
use warnings;
use strict;
use Net::WolframAlpha;
my $key = $ENV{WOLFRAM_ALPHA_API_KEY}
or die "set \$WOLFRAM_ALPHA_API_KEY in environment";
@kulp
kulp / pmvg.c
Created September 21, 2011 23:57
Poor man's valgrind
// "Poor man's valgrind"
#include "pmvg.h"
#include <stdlib.h>
#include <search.h>
static void *track_tree;
struct track_pair {
void *addr; size_t size;
};
static long bytes_lost;
@kulp
kulp / memshift.c
Created June 22, 2011 13:59
memcpy() with a bitshift specified
// positive shifts are left shifts
// left shifts are shifts higher into the word, which in a little-endian system
// is higher in memory
// XXX make endian-agnostic
void *memshift(void *dest, const void *src, size_t size, signed shift)
{
int shiftleft = shift > 0;
int shiftright = shift < 0;
int destbyteshift = (shiftleft * (+shift / CHAR_BIT));
int srcbyteshift = (shiftright * (-shift / CHAR_BIT));
@kulp
kulp / Makefile.cshim
Created May 27, 2011 18:28
Small cpp-based wrapper to provide C entry points for C++ libraries that don't need to be C++
CPPFLAGS += $(INCLUDE:%=-I%) $(DEFINES:%=-D%)
CXXFLAGS += -Wall -Wextra -Wno-unused
CC = gcc
LD = gcc
CFILES += $(wildcard *.c)
CXXFILES += $(wildcard *.cc)
CPP = g++ -x c++ -E -P
#DEFINES += CXX_VISIBLE=1