Skip to content

Instantly share code, notes, and snippets.

View Bill's full-sized avatar

Bill Burcham Bill

View GitHub Profile
@Bill
Bill / RingBufferSequential.java
Last active July 13, 2019 17:44
A non-thread-safe ring buffer thingie
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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / docker-compose.yml
Last active July 8, 2022 07:10
Run a local Hypothes.is annotation server (and the services it needs) via docker-compose
# This docker-compose.yml will run the Hypothes.is annotation server.
# (adapted from instructions here https://h.readthedocs.org/en/latest/INSTALL.html)
#
# Place this file in the working directory (clone of https://github.com/hypothesis/h)
# run with docker-compose up -d
#
# Now browse to Hypothes.is at http://192.168.59.103:8000/ and create an account
# You'll see the invitation email in Mailcatcher at http://192.168.59.103:1080/
# Click that invitation link and log in on your local Hypothes.is
# And you are ready to annotate!