Skip to content

Instantly share code, notes, and snippets.

@npryce
npryce / ElasticSearch Deadlock Test
Created Feb 28, 2011
Demonstrates deadlock when searching an ElasticSearch index immediately after creating it
View ElasticSearch Deadlock Test
package acceptance.giraffe.indexing;
import java.io.File;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.IndexMetaData;
@npryce
npryce / Repeat.java
Created Mar 1, 2011
Test to demonstrate search after refresh problem
View Repeat.java
package acceptance.giraffe.indexing;
import java.util.SortedMap;
import java.util.TreeMap;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
public class Repeat implements MethodRule {
@npryce
npryce / wip.py
Created May 28, 2011
Decorator to mark tests as work in progress for Python's Nose testing framework
View wip.py
from functools import wraps
from nose.plugins.attrib import attr
from nose.plugins.skip import SkipTest
def fail(message):
raise AssertionError(message)
def wip(f):
@wraps(f)
@npryce
npryce / java-generics-hell
Created Jul 29, 2011
Java Generics Hell
View java-generics-hell
import java.util.Comparator;
public class GenericsHell {
public static void compareSomeNumbers(Comparator<Integer> numberComparison) {
// ... elided ...
}
public static <T> Comparator<T> arbitraryOrder() {
return new Comparator<T>() {
@Override
@npryce
npryce / trees.lua
Created Nov 9, 2011
Random Trees for Codea
View trees.lua
function setup()
    seed = 1
end
function draw()
    background(136, 207, 224, 255)
    noStroke()
    fill(61, 109, 31, 255)
    rect(0, 0, WIDTH, 128)
@npryce
npryce / ZXMonospace.lua
Created Nov 27, 2011
Monospace bitmap font for Codea based on ZX Spectrum font (nostalgia!)
View ZXMonospace.lua
function ZXMonospace()
    return BitmapFont {
        height = 8,
        charSpacing = 0,
        lineSpacing = 0,
        
        ["!"] = {
            "        ",
            "   X    ",
@npryce
npryce / ZXProportional.lua
Created Nov 27, 2011
Proportional Font based on ZX Spectrum font
View ZXProportional.lua
function ZXProportional()
return BitmapFont {
height = 8,
charSpacing = 1,
lineSpacing = 0,
["!"] = {
" ",
"X",
@npryce
npryce / gist:3840872
Created Oct 5, 2012
Two-Dimensional Cucumber Table
View gist:3840872
|Key Press:
Playback |PAUSE |PLAY |FFWD |REW |STOP
----------+------+-------+--------+--------+------------
paused |paused|fwd x 1|fwd x 2 |rew x 1 |show live tv
fwd x 1 |paused|fwd x 1|fwd x 2 |rew x 1 |show live tv
fwd x 2 |paused|fwd x 1|fwd x 6 |rew x 1 |show live tv
fwd x 6 |paused|fwd x 1|fwd x 12|rew x 1 |show live tv
fwd x 12 |paused|fwd x 1|fwd x 30|rew x 1 |show live tv
fwd x 30 |paused|fwd x 1|fwd x 30|rew x 1 |show live tv
rew x 1 |paused|fwd x 1|fwd x 2 |rew x 2 |show live tv
@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):
@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: