Skip to content

Instantly share code, notes, and snippets.

View nfarring's full-sized avatar

Nathan Farrington nfarring

View GitHub Profile
@nfarring
nfarring / int128.cc
Created May 7, 2016 00:16
Overloading C++ operator<< to accept an __int128 from GCC/Clang
/**
* @file
*/
#include "int128.h"
/*
* http://stackoverflow.com/a/25115163
*/
std::ostream& operator<<(std::ostream& os, const __int128 i) noexcept
@nfarring
nfarring / iso8601.py
Last active August 29, 2015 14:14
Computes an ISO 8601-compatible datestamp for use with naming files.
from time import strftime as _strftime
def iso8601():
"""Returns an ISO 8601-compatible datestamp for use with naming files."""
return _strftime('%Y%m%dT%H%M%S')
@nfarring
nfarring / gist:c335fb004bf1720494c3
Created January 19, 2015 11:10
Bash wrapper around sqlite3 to run SQL commands
#!/usr/bin/env bash
# Create the file "database.sqlite3".
#
# Reference: http://ss64.com/bash/syntax.html
which sqlite3 &> /dev/null
if [ $? -eq 1 ]
then
echo "sqlite3 not found"
@nfarring
nfarring / gist:3302189
Created August 9, 2012 08:05
Parsing netstat in Linux
return_value = []
output = subprocess.Popen(
['netstat','--interfaces','all'],
stdout=subprocess.PIPE).communicate()[0]
#Kernel Interface table
#Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
#eth0 1500 0 1229230 0 0 0 1279754 0 0 0 BMRU
#lo 16436 0 163 0 0 0 163 0 0 0 LRU
lines = output.strip().splitlines()
lines.pop(0)
@nfarring
nfarring / gist:1904139
Created February 24, 2012 22:14
composer.json snippet for installing phpredis using composer
{
"type": "package",
"package": {
"name": "phpredis/phpredis",
"version": "2.1.3",
"dist": {
"url": "https://github.com/nicolasff/phpredis/zipball/2.1.3",
"type": "zip"
}
}
@nfarring
nfarring / Makefile
Created January 17, 2012 04:36
Intel RDTSC (Read Timestamp Counter) Instruction
main: main.c
.PHONY:
clean:
rm -f main
@nfarring
nfarring / Cores.ini
Created December 31, 2011 11:26
Failed attempt at creating a dependency tracker / Makefile generator tool for FPGAs
; special sections
[INCLUDE]
[FPGA]
device = xc6slx45
devicefamily = spartan6
package = csg324
speedgrade = -2
@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
@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 / 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