Skip to content

Instantly share code, notes, and snippets.

@npryce
npryce / build
Created Oct 14, 2014
Pass Git version info to SBT
View build
#!/bin/sh
set -e
version=`git describe --tags --match 'v*' --always --dirty=-monkeypatched | cut -c 2-`
sbt -Dversion=$version "$@"
View er-count-java
#!/bin/sh
set -e
for f in `find . -name '*.class'`
do
echo $f `basename $f .class|grep -Eo '[[:lower:]][eo]r([^[:lower:]]|$)'|wc -l`
done | sort -rnk 2
@npryce
npryce / gpio-cleanup
Created Jul 17, 2014
Script to unexport all gpio device directories that are exported to userspace
View gpio-cleanup
#!/bin/bash
set -e
for f in $(find /sys/class/gpio/ -name 'gpio[0-9]*')
do
echo $(basename $f | cut -c 5-) | tee /sys/class/gpio/unexport
done
@npryce
npryce / approval.py
Last active Aug 29, 2015
A quick-and-dirty Approval Testing tool for Python and Py.Test
View approval.py
import string
import os
from filecmp import cmp as file_contents_equal
def _extension(template_file, format):
if format is not None:
return "." + format
elif template_file is not None:
return os.path.splitext(template_file)[1]
@npryce
npryce / publish-to-bintray
Created Apr 25, 2014
A shell script to publish JARs to the Bintray Maven repository
View publish-to-bintray
#!/bin/sh
set -e
if [ ! -f ~/.bintray-login ]
then
echo save your bintray.com <userid>:<api-key> in ~/.bintray-login
exit 1
fi
groupid=${1:?group-id}
@npryce
npryce / NoisyThreadingPolicy.java
Last active Dec 12, 2015
Noisy threading policy for jMock
View NoisyThreadingPolicy.java
private static class NoisyThreadingPolicy implements ThreadingPolicy
{
private final Thread testThread = Thread.currentThread();
@Override public Invokable synchroniseAccessTo(final Invokable mockObject)
{
final StackTraceElement[] creationStack = stackTrace();
return new Invokable()
{
@npryce
npryce / merge-to-subdir
Last active Feb 13, 2018
Merge history from one Git repository as the history of a subdirectory of another Git repository
View merge-to-subdir
#!/bin/bash
# Usage: merge-to-subdir source-repo destination-repo subdir
#
# Merges the history of source-repo into destination-repo as the
# history of the subdirectory subdir.
#
# source-repo can be local or remote.
# destination-repo must be local to the machine.
# subdir can be a relative path, in which case intermediate
@npryce
npryce / property-based-testing-tools.md
Last active Jun 7, 2021
Property-Based Testing Tools
View property-based-testing-tools.md

If you're coming to the Property-Based TDD As If You Meant It Workshop, you will need to bring a laptop with your favourite programming environment, a property-based testing library and, depending on the language, a test framework to run the property-based-tests.

Any other languages or suggestions? Comment below.

.NET (C#, F#, VB)

Python:

@npryce
npryce / qc.py
Created Nov 3, 2012
QuickCheck for Python and Py.Test
View qc.py
def dicts(d):
keys, value_iters = zip(*d.items())
return (dict(zip(keys,values)) for values in zip(*value_iters))
def property(test_fn=None, tests=100):
def bind_parameters(test_fn):
arg_bindings = dicts(test_fn.__annotations__)
def bound_test_fn():
for args in itertools.islice(arg_bindings, tests):