Skip to content

Instantly share code, notes, and snippets.

@sw
sw / gist:1514422
Created December 23, 2011 15:03
SLRE: is_any_of() with escape character support
static int
is_any_of(const unsigned char *p, int len, const char *s, int *ofs)
{
int i, ch;
ch = s[*ofs];
for (i = 0; i < len; i++)
if (p[i] == ch) {
(*ofs)++;
@sw
sw / gist:1244446
Created September 27, 2011 06:09
python snippet to enumerate serial ports on Windows
import itertools
import _winreg as winreg
def enumerate_serial_ports():
path = 'HARDWARE\\DEVICEMAP\\SERIALCOMM'
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path)
ports = []
for i in itertools.count():
try:
val = winreg.EnumValue(key, i)