Skip to content

Instantly share code, notes, and snippets.

View kdrakon's full-sized avatar

Sean Policarpio kdrakon

View GitHub Profile
@kdrakon
kdrakon / SprayWithJettyEmbedded.scala
Created February 19, 2014 22:38
Using Spray (1.2.0) with Jetty 9 Embedded
object Main extends App {
val jettyServer = new Server(8080)
/** Serve some HTML along side the Spray Servlet **/
val htmlHandler = new ResourceHandler()
// here, my HTML files are in a 'web' folder under src/main/resources/web
htmlHandler.setResourceBase(ClassLoader.getSystemResource("web").toString())
htmlHandler.setDirectoriesListed(true)
@kdrakon
kdrakon / KindaLikeASelfRefreshingCache.java
Created April 10, 2014 15:49
A Guava cache that defaults to old values in the event of failure
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.util.concurrent.ListenableFuture;
@kdrakon
kdrakon / GuavaArrayListMultiMapFromToString.java
Last active November 17, 2015 14:39
I needed to re-create an ArrayListMultiMap from some real-world data to test something locally, but I only had access remotely via the toString method
class GuavaArrayListMultiMapFromToString {
static ArrayListMultimap<String, String> toArrayListMultimap(final String toString)
{
final ArrayListMultimap<String, String> map = ArrayListMultimap.create();
final Pattern pattern = Pattern.compile("\\w+=\\[.+?\\]");
final Matcher matcher = pattern.matcher(data);
while(matcher.find())
{
final String group = matcher.group();
@kdrakon
kdrakon / blab.md
Last active February 8, 2016 20:50
HotLikeScoreCalculator [http://blabr.io?5d695c8e5cc08bfde48e]

HotLikeScoreCalculator

@kdrakon
kdrakon / AwsPipelineClusterManager.scala
Last active April 4, 2016 02:38
Playing around with AWS SDK for ECS
package aws.playground
import aws.playground.AwsPipelineClusterManager._
import com.amazonaws.regions.RegionUtils
import com.amazonaws.services.autoscaling.AmazonAutoScalingClient
import com.amazonaws.services.autoscaling.model.{CreateAutoScalingGroupRequest, CreateLaunchConfigurationRequest, DeleteAutoScalingGroupRequest, DeleteLaunchConfigurationRequest}
import com.amazonaws.services.ecs.AmazonECSClient
import com.amazonaws.services.ecs.model.{CreateClusterRequest, CreateClusterResult, DeleteClusterRequest, DeleteClusterResult}
@kdrakon
kdrakon / RouterAutoChannel.scala
Created July 10, 2016 03:05
How I believe routers have implemented 'Auto Channel'
val accessPoints = Seq(???)
def autoChannel(accessPoints: Seq[AccessPoint]): Channel = {
accessPoints.groupBy(_.channel)
.maxBy{ case (channel, aps) => aps.size }
._1
}

Keybase proof

I hereby claim:

  • I am kdrakon on github.
  • I am kdrakon (https://keybase.io/kdrakon) on keybase.
  • I have a public key whose fingerprint is 3696 F8F1 D728 6671 EBA2 97B8 5879 13B5 C5C6 51B7

To claim this, I am signing this object:

@kdrakon
kdrakon / ConsistentHashGroupedStreams.scala
Created September 6, 2016 05:29
Example of Consistent Hashing for Akka groupBy Streams
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.{Executors, TimeUnit}
import akka.actor.{ActorSystem, Props}
import akka.routing.ConsistentHash
import akka.stream.actor._
import akka.stream.scaladsl.{Flow, GraphDSL, RunnableGraph, Sink, Source}
import akka.stream.{ActorMaterializer, ClosedShape, ThrottleMode}
import com.kifi.franz.{MessageId, SQSMessage}
@kdrakon
kdrakon / SerdeFunction.java
Created December 21, 2017 01:16
A Kafka Serde Java 8 Function
import org.apache.kafka.common.serialization.Deserializer;
import org.apache.kafka.common.serialization.Serde;
import org.apache.kafka.common.serialization.Serializer;
import java.util.Map;
import java.util.function.Function;
public class SerdeFunction<T> implements Serde<T> {
private final Function<T, byte[]> serializer;
@kdrakon
kdrakon / JsonSerdeForAvroClasses.java
Created December 21, 2017 01:17
A Kafka Serde for turning Avro-generated classes into JSON objects (only does serialization)
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.kafka.streams.kstream.ValueMapper;
import java.nio.charset.Charset;
public class JsonSerdeForAvroClasses<T> {
public static <T> JsonSerdeForAvroClasses<T> gen() {