Skip to content

Instantly share code, notes, and snippets.

View jvz's full-sized avatar

Matt Sicker jvz

View GitHub Profile
package com.example
import akka.NotUsed
import akka.actor.ActorRef
import akka.pattern.AskableActorRef
import akka.stream.scaladsl.Source
import akka.util.Timeout
import scala.reflect.ClassTag
def unpaginate[S, T](s: S)
(fetch: S => Future[(Option[S], Seq[T])])
(implicit context: ExecutionContext): Source[T, NotUsed] =
Source.unfoldAsync(Option(s)) {
case None => Future.successful(None)
case Some(token) => fetch(token).map(Some(_))
}.mapConcat(_.toList).async
@jvz
jvz / json.scala
Created July 1, 2017 18:16
Example of using Scala Parser Combinators to parse JSON into an AST
import scala.util.parsing.combinator._
sealed trait Json
case object JsonNull extends Json
final case class JsonBoolean(b: Boolean) extends Json
final case class JsonString(s: String) extends Json
final case class JsonNumber(x: BigDecimal) extends Json
final case class JsonArray(elems: List[Json]) extends Json
final case class JsonObject(entries: List[(String, Json)]) extends Json
@jvz
jvz / ObservablePublisher.java
Created April 5, 2017 20:30
Demonstrates the basic idea behind converting an RxJava 1.x Observable into a Reactive Streams compliant Publisher.
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import rx.Observable;
/**
* Wrapper for {@link Observable} to bridge to the Reactive Streams API.
*/
public class ObservablePublisher<T> implements Publisher<T> {
@jvz
jvz / ps1.sh
Created February 24, 2017 03:47
if [[ ! -f ~/.git-prompt.sh ]]; then
curl -o ~/.git-prompt.sh https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
fi
. ~/.git-prompt.sh
function get_version_ctl_branch() {
local dir="$PWD"
local vcs
local nick
package com.example;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import java.util.stream.Stream;
import lombok.extern.log4j.Log4j2;
import org.reactivestreams.Publisher;
@jvz
jvz / SecureSchedulers.java
Created February 9, 2017 22:10
Wrapped Reactor Schedulers for use with Spring Security
package com.example;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.springframework.security.concurrent.DelegatingSecurityContextExecutorService;
import org.springframework.security.core.context.SecurityContext;
@jvz
jvz / AbstractAppender.java
Created January 7, 2017 04:30
Generic builder DSL
public abstract class AbstractAppender extends AbstractFilterable implements Appender {
public abstract static class Builder<T extends AbstractAppender, B extends Builder<T, B> & org.apache.logging.log4j.core.util.Builder<T>>
extends AbstractFilterable.Builder<T, B> {
// ...
}
}
:h hidden
- allows you to keep buffers open
:ls
- lists open buffers
:b (:buffer)
- edit buffer N from list (jump between buffers)
- can also use :Nb for buffer number N
@jvz
jvz / blueprint.xml
Created May 2, 2016 15:04
Blueprint file for configuring Hazelcast in Camel
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<ext:property-placeholder/>
<bean id="hazelcastInstance" class="com.hazelcast.core.Hazelcast" factory-method="newHazelcastInstance" destroy-method="shutdown">
<argument>
<bean class="com.hazelcast.config.FileSystemXmlConfig">