Skip to content

Instantly share code, notes, and snippets.

Bill Burcham Bill

Block or report user

Report or block Bill

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Bill
Bill / window.kt
Created Jul 22, 2019
CoroutineScope.timeWindow(producer: ReceiveChannel<T>, delayMillis: Long): ReceiveChannel<List<T>>
View window.kt
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancelChildren
import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.channels.produce
import kotlinx.coroutines.channels.ticker
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.selects.select
import java.time.LocalDateTime
@Bill
Bill / VirtualTimeSchedulerInaccurate.java
Last active Jul 5, 2019
Project Reactor VirtualTimeScheduler subclass that introduces (controlled) error into schedule times in order to cause changes to task interleaving.
View VirtualTimeSchedulerInaccurate.java
package com.thoughtpropulsion.reactrode;
import static com.thoughtpropulsion.reactrode.Functional.returning;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import reactor.core.Disposable;
@Bill
Bill / ConnectableFluxTest.java
Last active Jul 5, 2019
Test Project Reactor ConnectableFlux. State space exploration brought to you by `VirtualTimeSchedulerInaccurate` and changing `new Random(1)` to `new Random()`.
View ConnectableFluxTest.java
package com.thoughtpropulsion.reactrode.rxperiment;
import static com.thoughtpropulsion.reactrode.Functional.returning;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.nanoTime;
import static org.assertj.core.api.Assertions.assertThat;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.time.Duration;
@Bill
Bill / RingBufferSequential.java
Last active Jul 13, 2019
A non-thread-safe ring buffer thingie
View RingBufferSequential.java
package com.thoughtpropulsion.reactrode;
import static com.thoughtpropulsion.reactrode.Functional.returning;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import io.vavr.Tuple2;
import io.vavr.control.Option;
@Bill
Bill / scratch_38.java
Created Jun 17, 2019
I don't think the changes to genericize Execution does what we want https://github.com/apache/geode/pull/3715
View scratch_38.java
import java.math.BigInteger;
import java.util.Collections;
import org.apache.geode.cache.execute.Execution;
import org.apache.geode.cache.execute.FunctionService;
class Scratch {
public static void main(String[] args) {
final Execution<String, String, String> execution = FunctionService.onRegion(null);
View TypeToolsTest.java
import static net.jodah.typetools.TypeResolver.resolveRawArgument;
public class Core {
interface Handler<T> {
void process(T x);
}
void p1(final String s) {}
void p1(final int i) {}
@Bill
Bill / MonoidMenagerie.java
Last active Jun 19, 2019
Monoid Menagerie, or, the uncanny usefulness of four lines of Java
View MonoidMenagerie.java
import java.util.Comparator;
import java.util.List;
import java.util.function.BinaryOperator;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/*
@Bill
Bill / Memoize.java
Last active May 24, 2019
A couple memoization functions for Java Suppliers.
View Memoize.java
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
class Memoize {
private Memoize() {}
/*
Props to AOL Cyclops Memoize for this little trick: using the UNSET reference
value as the sentinel for an uninitialized cache value. This approach allows memoization
@Bill
Bill / EnhancedForLoopOverMapValues.java
Created May 24, 2019
Using JSR 201 enhanced for loop to iterate over Map values
View EnhancedForLoopOverMapValues.java
import java.util.HashMap;
import java.util.Map;
class Scratch {
interface Pool {
void basicDestroy(boolean keepAlive);
}
static class PoolImpl implements Pool {
@Override
public void basicDestroy(final boolean keepAlive) {
@Bill
Bill / DoesOptionalObeyFunctorLaws.java
Last active May 1, 2019
Optional, introduced along with Stream and Function, in Java 8, has a map() method. Does it obey the functor laws, particularly the one pertaining to function composition?
View DoesOptionalObeyFunctorLaws.java
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class Scratch {
/*
A method that converts a String to an Integer.
You can’t perform that action at this time.