Skip to content

Instantly share code, notes, and snippets.

View twpayne's full-sized avatar

Tom Payne twpayne

  • Zürich, Switzerland
  • 17:45 (UTC +02:00)
View GitHub Profile
@twpayne
twpayne / main_test.go
Last active December 4, 2023 09:45
CockroachDB bulk insert test case
package main
import (
"bytes"
"database/sql"
"flag"
"html/template"
"strconv"
"strings"
"testing"
@twpayne
twpayne / main.go
Last active March 29, 2019 16:26
github.com/lib/pq race condition
package main
// Run this with:
// $ go test -count=1 -race -timeout=2s -dsn=postgresql://... .
import (
"context"
"database/sql"
"flag"
"strconv"
@twpayne
twpayne / main.go
Created February 20, 2019 23:43
github.com/twpayne/go-xdg trivial example
package main
import (
"fmt"
xdg "github.com/twpayne/go-xdg"
)
func main() {
bds, err := xdg.NewBaseDirectorySpecification()
package argbench
import (
"testing"
)
// n limits the size of the constructed arrays, to prevent the benchmarks from
// measuring memory bandwidth instead of performance.
const n = 1024
@twpayne
twpayne / argbench_test.go
Last active June 14, 2016 20:58
Golang benchmark test
package argbench
import (
"testing"
)
// n limits the size of the constructed arrays, to prevent the benchmarks from
// measuring memory bandwidth instead of performance.
const n = 1024
@twpayne
twpayne / arduino_assemble.py
Created March 21, 2015 15:19
Rough-and-ready approximation to Arduino's multi-file sketch assembly process
#!/usr/bin/python
import glob
import re
import os
import sys
def assemble_paths(paths):
"""Assemble multiple files together into a main sketch. paths is a list
@twpayne
twpayne / xlist.c
Created December 8, 2014 12:10
Doubly-linked list with a single word per node
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
/* on Mac OS X sizeof(int) < sizeof(int *) so make sure we use a large enough integer! */
typedef int64_t integer_t;
typedef struct {
int value;
integer_t nextprev;
@twpayne
twpayne / .slate
Last active August 29, 2015 14:01
# Configs
config defaultToCurrentScreen true
config checkDefaultsOnLoad true
# Position Aliases
alias one move screenOriginX;screenOriginY screenSizeX;screenSizeY
@twpayne
twpayne / xmonad.hs
Created November 21, 2012 20:16
Tom's XMonad config
import Data.Bits ((.|.))
import qualified Data.Map as M
import System.Exit
import XMonad hiding (Tall)
import XMonad.Actions.FocusNth
import XMonad.Actions.Search
import XMonad.Actions.Submap
import XMonad.Config.Gnome
import XMonad.Core
import XMonad.Hooks.ManageDocks
@twpayne
twpayne / awb.py
Created October 25, 2012 14:24 — forked from fredj/awb.py
AWB (Airway bill) number validation
import re
def valid(awb):
m = re.match('\d{3}(?P<serial>\d{7})(?P<check>\d)\Z', awb)
return m and int(m.group('serial')) % 7 == int(m.group('check'))