Skip to content

Instantly share code, notes, and snippets.

View Bill's full-sized avatar

Bill Burcham Bill

  • http://memerocket.com/
  • Tucson, AZ
View GitHub Profile
@Bill
Bill / scratch_41.java
Last active March 4, 2021 18:15
An experiment with a ThreadPoolExecutor and various sync/async workQueues for https://cwiki.apache.org/confluence/display/GEODE/Thread+Pools
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
@Bill
Bill / set-intersection.java
Last active August 21, 2019 22:30
one way to intersect sets
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 August 10, 2019 21:16
Spring configuration of RSocketServerFactory that runs WEBSOCKET transport
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 July 31, 2019 14:41
Kotlin turnstile state machine using fun to implement states
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 July 31, 2019 15:12
Kotlin turnstile state machine using a sealed class
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 July 26, 2019 23:39
Demonstrate a Java-callable wrapper on a Kotlin coroutine
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 July 23, 2019 23:45
use CompletableDeferred to do request-response style messaging to a coroutine
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 July 22, 2019 22:50
CoroutineScope.timeWindow(producer: ReceiveChannel<T>, delayMillis: Long): ReceiveChannel<List<T>>
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 July 5, 2019 17:55
Project Reactor VirtualTimeScheduler subclass that introduces (controlled) error into schedule times in order to cause changes to task interleaving.
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 July 5, 2019 17:50
Test Project Reactor ConnectableFlux. State space exploration brought to you by `VirtualTimeSchedulerInaccurate` and changing `new Random(1)` to `new Random()`.
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;