Skip to content

Instantly share code, notes, and snippets.

Avatar

Bill Burcham Bill

View GitHub Profile
@Bill
Bill / set-intersection.java
Last active Aug 21, 2019
one way to intersect sets
View set-intersection.java
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
class Scratch {
public static void main(String[] args) {
final Set<Integer> a = Set.of(1, 2, 3);
final Set<Integer> b = Set.of(3, 4, 5);
System.out.println("intersection: " + intersect(a, b));
}
@Bill
Bill / ServerConfiguration1.java
Created Aug 10, 2019
Spring configuration of RSocketServerFactory that runs WEBSOCKET transport
View ServerConfiguration1.java
package com.thoughtpropulsion.reactrode.server;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import java.util.stream.Collectors;
import com.thoughtpropulsion.reactrode.model.Cell;
import com.thoughtpropulsion.reactrode.model.CoordinateSystem;
import com.thoughtpropulsion.reactrode.model.GameOfLife;
@Bill
Bill / state-machine-function-states.kt
Created Jul 31, 2019
Kotlin turnstile state machine using fun to implement states
View state-machine-function-states.kt
package functional
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.channels.produce
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.selects.select
@FunctionalInterface
@Bill
Bill / state-machine.kt
Last active Jul 31, 2019
Kotlin turnstile state machine using a sealed class
View state-machine.kt
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.channels.produce
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.selects.select
sealed class State {
/**
* Process the first input from the channel(s) [perform a side-effect] and return a new functional.State
@Bill
Bill / CallCoroutineFromJava.java
Last active Jul 26, 2019
Demonstrate a Java-callable wrapper on a Kotlin coroutine
View CallCoroutineFromJava.java
import static java.lang.Thread.sleep;
import java.time.LocalDateTime;
import java.util.Collection;
public class CallCoroutineFromJava {
public static void main(String[] args) throws InterruptedException {
final JavaCallableCoroutineScope jccs = new JavaCallableCoroutineScope();
@Bill
Bill / deferred.kt
Created Jul 23, 2019
use CompletableDeferred to do request-response style messaging to a coroutine
View deferred.kt
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.channels.produce
import kotlinx.coroutines.channels.ticker
import kotlinx.coroutines.selects.select
import java.time.LocalDateTime
fun log2(msg:String) {
println("$msg in thread ${Thread.currentThread()}")
}
@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;
You can’t perform that action at this time.