Skip to content

Instantly share code, notes, and snippets.

View pettermahlen's full-sized avatar

Petter Måhlén pettermahlen

View GitHub Profile
import Foundation
/// Utility to catch invalid multithreaded access to non-thread-safe code.
///
/// `MultiThreadedAccessDetector` guards a critical region, verifying that it is never invoked by two different threads.
/// If this happens, it crashes in debug builds. In release builds, it has no effect (and also no overhead, as long as
/// it’s only used within one module).
///
/// Copies of a `MultiThreadedAccessDetector` share the same underlying mutex, and hence their critical region is the
/// union of the critical regions of all copies.
@Test
public void shouldDisposeMultiThreadedEventSourceSafely() throws Exception {
// event source that just pushes stuff every X ms on a thread.
RecurringEventSource source = new RecurringEventSource();
final Builder<String, TestEvent, TestEffect> builder = Mobius
.loop(update, effectHandler).eventSource(source);
$ bash <(curl -s https://codecov.io/bash)
_____ _
/ ____| | |
| | ___ __| | ___ ___ _____ __
| | / _ \ / _` |/ _ \/ __/ _ \ \ / /
| |___| (_) | (_| | __/ (_| (_) \ V /
\_____\___/ \__,_|\___|\___\___/ \_/
0db33a1
@AutoValue
public abstract class EqualsBreaker {
EqualsBreaker() {}
public static EqualsBreaker create(Set<HostAndPort> hosts) {
return new AutoValue_EqualsBreaker(ImmutableSet.copyOf(hosts));
}
public abstract Set<HostAndPort> hosts();
}
@pettermahlen
pettermahlen / gist:2400295
Created April 16, 2012 17:50
AbstractThrowingIterator
public abstract class AbstractThrowingIterator<T> extends UnmodifiableIterator<T> {
private State state = State.NOT_READY;
/** Constructor for use by subclasses. */
protected AbstractThrowingIterator() {}
private enum State {
/** We have computed the next element and haven't returned it yet. */
READY,
@pettermahlen
pettermahlen / cucumber-jvm-117 patch
Created December 9, 2011 09:03
Snippet Generator Fix for issue cucumber-jvm 117
diff --git a/core/src/main/java/cucumber/runtime/snippets/SnippetGenerator.java b/core/src/main/java/cucumber/runtime/snippets/SnippetGenerator.java
index 2a20435..ce647d8 100644
--- a/core/src/main/java/cucumber/runtime/snippets/SnippetGenerator.java
+++ b/core/src/main/java/cucumber/runtime/snippets/SnippetGenerator.java
@@ -87,11 +87,14 @@ public abstract class SnippetGenerator {
protected String sanitizeFunctionName(String functionName) {
StringBuilder sanitized = new StringBuilder();
- sanitized.append(Character.isJavaIdentifierStart(functionName.charAt(0)) ? functionName.charAt(0) : SUBST);
- for (int i = 1; i < functionName.length(); i++) {