Skip to content

Instantly share code, notes, and snippets.

@dhemery
dhemery / LambdaExample.java
Last active July 3, 2019 05:47
Demonstrate that the runtime type of a lambda expression depends on the order of execution of lambda expressions
// Run this first with no args, then with 1 or more args
public class LambdaExample {
public static void main(String[] args) {
if(args.length > 0) {
lambdaA();
lambdaB();
} else {
lambdaB();
lambdaA();
}
@dhemery
dhemery / GenericMethodTypeInference.java
Created April 21, 2019 17:51
Effects of Different Ways of Expressing Type Dependence in Generic Methods
package com.dhemery.generics;
import java.util.Objects;
import java.util.function.Predicate;
public class GenericMethodTypeInference {
// Subject type and predicate input type must be the same.
<S> boolean test(S subject, Predicate<S> criterion) {
return criterion.test(subject);
@dhemery
dhemery / Auto-detectable-port-names.md
Last active June 3, 2017 05:52
Notes about writing Bitwig controller scripts for the Novation Impulse MIDI controller

MacOS

Input Port Names

  • Impulse␣␣Impulse␣ (for the USB port)
  • Impulse␣␣Impulse␣MIDI In␣ (for the DIN port, I think)

Output Port Names

  • Impulse␣␣Impulse␣ (for the USB port)
@dhemery
dhemery / Expectations on Matcher
Created May 3, 2015 18:22
Setting expectations on Matchers in JMock
new Expectations() {{
// allowing(matcher) treats the matcher not as the receiver,
// but as a matcher on receivers, so must use same(matcher)
//
// No matches(input) is available, so must use method("matches")
//
// No with(input) is available, so must use with(equalTo(input))
allowing(same(matcher)).method("matches").with(equalTo(input));
will(returnValue(false));
}};
@dhemery
dhemery / hamburger-disguise.txt
Last active August 29, 2015 14:16
"Hamburger Disguise" lyrics
Hamburger Disguise
Music and lyrics by Dale Emery
The girl in the box says
"Welcome to the drive-up window.
Can I take your order?"
"One coke, no ice,
and a burger to go."
"Thank you. Please come again."
Driving down the avenue,
@dhemery
dhemery / config.rb
Last active January 2, 2016 15:58
Unable to make middleman-blog custom_collections work.
blog.custom_collections = {
topic: {
link: 'topic/:topic/index.html',
template: 'topics.html'
}
}
@dhemery
dhemery / Gherkin in Java
Created July 18, 2013 22:19
Suddenly my tests became Gherkin. I like it for these two tests. Will I like it for more?
@Test
public void copiesPlainFilesFromSourceRootToSiteRoot() {
given(sourceFile("foo.txt"), withContent("foo content"));
when(jogger, runs());
then(siteFile("foo.txt"), content(), is("foo content"));
}
@Test
public void copiesPlainFilesFromSourceSubdirectoryToCorrespondingSiteSubdirectory() {
given(sourceFile("my/subdirectory/foo.txt"), withContent("subdirectory foo content"));
@dhemery
dhemery / hamcrest-matcher-style.java
Created December 10, 2011 00:25
DSLs to verify and wait for conditions: Which style do you prefer?
verifyThat(masterView, isPresent());
verifyThat(masterView, eventually(isPresent()));
// What would the "when the subject satisfies a condition" example look like? Maybe this?
when(masterView, isPresent()).touch();
@dhemery
dhemery / Applying Rules
Created December 14, 2010 23:35
How to write and apply JUnit Rules.
public class MyTest {
@Rule
public MethodRule screenshot = new ScreenshotOnFailureRule();
@Test
public void myTest() { ... }
...
}