Note: the latest version of this document is at http://natpryce.com/articles/000812.html
Here's some code that gets and uses a value from a synchronous call or built in data structure:
function to_be_refactored() {
var x;
...
x = get_x();
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): |
|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 |
function ZXProportional() | |
return BitmapFont { | |
height = 8, | |
charSpacing = 1, | |
lineSpacing = 0, | |
["!"] = { | |
" ", | |
"X", |
function ZXMonospace() | |
return BitmapFont { | |
height = 8, | |
charSpacing = 0, | |
lineSpacing = 0, | |
["!"] = { | |
" ", | |
" X ", |
function setup() | |
seed = 1 | |
end | |
function draw() | |
background(136, 207, 224, 255) | |
noStroke() | |
fill(61, 109, 31, 255) | |
rect(0, 0, WIDTH, 128) |
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 |
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 { |
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; |
// React decides if it has a DOM on loading, so if we always need to | |
// initialise JSDOM before loading it. | |
var testdom = require('testdom'); | |
testdom('<html><body></body></html>'); | |
// But React hates you even more than that... it caches the rendered component | |
// in the DOM and if the same type of component with the same key is rendered at | |
// into the same element, then it uses the cached instance, not the just rendered | |
// instance. Even if the props are different. So the instance being tested will | |
// not be exercised. |
Note: the latest version of this document is at http://natpryce.com/articles/000812.html
Here's some code that gets and uses a value from a synchronous call or built in data structure:
function to_be_refactored() {
var x;
...
x = get_x();