Scripts and Snippets

Troy D. Hanson <tdh@tkhanson.net>

scripts and snippets

Back to tkhanson.net main page.

About

These are miscellaneous small scripts and snippets that I’ve written on Linux and OS X. These are all placed in the public domain.

Download options

Snippets

Examples of using common libraries and other reusable bits:

dlsym

example of using dlsym()

C

lemon

example of using the Lemon parser generator

C

udp

example of UDP client and server

C

tcp

example of TCP client and server

C

ifinfo

code to list network interfaces, their IPv4/v6 addresses and MACs

C

dns

example of doing DNS lookup

C

sigio

example of signal driven I/O notification

C

asm

a few x86 assembly programs that call C library functions or are called from C

asm

inotify

example of getting inotify file events (Linux 2.6.13 and higher)

C

mworkers

example of a parent process managing multiple worker processes

C

pcre

example of using pcre library

C

pcap

example of using libpcap to capture packets

C

readline

example of using readline library

C

unixdomain

example of UNIX domain socket client and server notes

C

controlport

a control port library: an administrative interface to a server

C

bloom

builds a Bloom filter from lines of one text file, tests lines of another file on it

C

timeseries

a time series library, series comprised of arbitrary elements

C

entropy

measuring entropy of a byte stream notes

C

zlib

example of implementing a simple gzip/gunzip using the zlib C API

C

tconf

simple function to read key-value configuration file entries

C

rw_wrap

macros to wrap read/write, which loop until "len" bytes are read or written

C

iconv

example of using the iconv library

C

iscan

an incremental grep that reads a stream piecemeal scanning for a pattern

C

slurp

example of using read or mmap to "slurp" a whole file

C

pexit

a C program that gets signalled when its parent exits using prctl

C

utf8

macros for utf8 handling including character length, validity and utf32 conversion

C

looper

example of iterating over lines of input from file or stdin using readline

C

Scripts

fifor

run commands whenever a fifo is readable (useful when triggered by a vim hotkey) notes

Perl

downsample

reduce a text file to x% of its lines (default 10%)

Perl

md5watch

list files changed since last run notes

Perl

mailpl

send email with attachments, configurable from address, etc

Perl

anb

list lines in file A but not in file B

Perl

bin2hex

convert stdin to hex bytes

Perl

hex2bin

convert hex args to binary bytes on stdout

Perl

fcut

print region (from position s of length l) from a file

Perl

pagehits

parse access.log and store daily hits for each url, or view cumulative hits

Perl

remember

type "remember", run some commands you want to remember, then "remember -s" to save them notes

sh

rrd

sample of using rrdtool

Perl

ditaa

embedding ditaa diagrams into Asciidoc documents notes

ditaa

setup

configure some of my preferences in .bash_profile, .gdbinit, .vimrc and .inputrc

sh

Other resources

  1. Virtual Memory in a Nutshell slides I wrote in 2009.