Skip to content

Instantly share code, notes, and snippets.

@npryce
npryce / merge-to-subdir
Last active February 22, 2024 17:23
Merge history from one Git repository as the history of a subdirectory of another Git repository
#!/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 / NoisyThreadingPolicy.java
Last active December 12, 2015 03:28
Noisy threading policy for jMock
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 / publish-to-bintray
Created April 25, 2014 08:28
A shell script to publish JARs to the Bintray Maven repository
#!/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 / approval.py
Last active August 29, 2015 14:02
A quick-and-dirty Approval Testing tool for Python and Py.Test
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 / gpio-cleanup
Created July 17, 2014 23:39
Script to unexport all gpio device directories that are exported to userspace
#!/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
#!/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 / build
Created October 14, 2014 09:59
Pass Git version info to SBT
#!/bin/sh
set -e
version=`git describe --tags --match 'v*' --always --dirty=-monkeypatched | cut -c 2-`
sbt -Dversion=$version "$@"
@npryce
npryce / MerchantOfVenice.java
Last active August 29, 2015 14:09
merchant-of-venice
public interface Prickable {
void prick();
boolean isBleeding();
}
public interface Ticklable {
void tickle();
boolean isLaughing();
}
@npryce
npryce / LoggerTest.java
Last active August 29, 2015 14:17
How to create a Log4J Logger for unit testing Java code that logs
LoggingEvent loggedEvent = null;
private Logger capturingLogger() {
return new Logger("testing") {
{
level = Level.ALL;
repository = mock(LoggerRepository.class);
when(repository.isDisabled(anyInt())).thenReturn(false);
}