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 / RingBufferSequential.java
Created Jun 20, 2019
A non-thread-safe ring buffer thingie
View RingBufferSequential.java
package com.thoughtpropulsion.reactrode;
import static com.thoughtpropulsion.reactrode.JavaLang.returning;
import io.vavr.control.Option;
/**
* Not thread safe. A customized ring-buffer for {@link GameStateWithBackPressure}
*
* @param <T>
@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 / 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 / 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 / docker-compose.yml
Last active May 2, 2019
Run a local Hypothes.is annotation server (and the services it needs) via docker-compose
View docker-compose.yml
# 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!
@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.
@Bill
Bill / flatMapNulls.java
Created Apr 24, 2019
Use flatMap() to elide nulls in a Stream
View flatMapNulls.java
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class Scratch {
public static void main(String[] args) {
final List<String> original =
Stream.of("a", "b", null, "c")
.collect(Collectors.toList());
@Bill
Bill / EnumSetFormat.java
Created Apr 4, 2019
Creates an EnumSet with a couple elements and prints it in String and OutputStream format.
View EnumSetFormat.java
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.EnumSet;
class Scratch {
enum Fruit {APPLE, ORANGE};
public static void main(String[] args) throws IOException {
final EnumSet<Fruit> fruits = EnumSet.of(Fruit.APPLE, Fruit.ORANGE);
You can’t perform that action at this time.