Skip to content

Instantly share code, notes, and snippets.

View nfarring's full-sized avatar

Nathan Farrington nfarring

View GitHub Profile
@nfarring
nfarring / gist:1110611
Created July 27, 2011 23:41
Python thread example
#!/usr/bin/env python
# This script creates a daemon thread named 'watchdog_timer' that runs the watchdog_timer() function.
# The main thread sleeps in an infinite loop until you press control-C.
# Since the watchdog_timer thread is a daemon, exiting the main thread will exit the entire process.
import threading
import time
def watchdog_timer():
@nfarring
nfarring / index.html
Created July 29, 2011 06:17
Ubuntu Apache default index.html file
<html><body><h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>
@nfarring
nfarring / wordsize.c
Created August 24, 2011 19:22
Prints the sizes of various integral types in the C language on a POSIX/Linux/UNIX machine.
#include <stdint.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("sizeof(char): %lu\n", sizeof(char));
printf("sizeof(unsinged char): %lu\n", sizeof(unsigned char));
printf("sizeof(signed char): %lu\n", sizeof(signed char));
printf("sizeof(int8_t): %lu\n", sizeof(int8_t));
printf("sizeof(uint8_t): %lu\n", sizeof(uint8_t));
printf("sizeof(short): %lu\n", sizeof(short));
@nfarring
nfarring / gist:1169363
Created August 24, 2011 21:52
Register a signal handler for SIGINT.
#include <stdlib.h>
#include <signal.h>
/*
* Gracefully exits when Ctrl+C is pressed.
*/
void sigint_handler(int signum) {
exit(0);
}
@nfarring
nfarring / bind.c
Created August 24, 2011 22:27
Templates for C sockets
#include <stdio.h> // PERROR(3)
#include <stdlib.h> // EXIT(3)
#include <sys/socket.h> // BIND(2)
int retval = bind(
/* int sockfd */
/* const struct sockaddr *addr */
/* socklen_t addrlen */
);
if (retval == -1) {
@nfarring
nfarring / gist:1175192
Created August 27, 2011 09:38
Python script template
#!/usr/bin/env python
# http://docs.python.org/dev/library/argparse.html
import argparse
if __name__=='__init__':
parser = argparse.ArgumentParser(description='')
args = parser.parse_args()
print(args)
@nfarring
nfarring / barcode.xsd
Created September 4, 2011 06:30
Barcode XML Schema
<xs:simpleType name="UPC-E-Barcode">
<xs:annotation>
<xs:documentation>
Reference: http://www.barcodeisland.com/upce.phtml
The UPC-E barcode has 7 digits.
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:token">
<xs:pattern value="[0-9]{7}"/>
</xs:restriction>
@nfarring
nfarring / Makefile
Created September 12, 2011 21:37
ebert: Ethernet Bit Error Rate Tester
CFLAGS=-std=gnu99 -O3
LDFLAGS=-lrt -lgmp
.PHONY: all
all: ebert
ebert: ebert.c time.o profile.o
time.o: time.c time.h
@nfarring
nfarring / README
Created October 28, 2011 23:13
Bridges two Xilinx PicoBlaze microcontrollers via their I/O ports using a pair of 16x8 FIFOs
This turned out not to be as useful as just using the raw FIFO interface directly and letting each PicoBlaze do its own I/O logic.
@nfarring
nfarring / uartbert.py
Created November 9, 2011 01:06
Serial Bit Error Rate Tester in Python
#!/usr/bin/env python
#
# Measure the bit error rate if a serial port in loopback.
#
import serial
import sys
import traceback