Skip to content

Instantly share code, notes, and snippets.

Christopher Hunt huntc

View GitHub Profile
@huntc
huntc / events.scala
Last active Jul 13, 2018
OO inheritance for data modelling - describes types of events that share a common identifier
View events.scala
sealed abstract class Event(val id: Int)
final case class CountersUpdated(override val id: Int,
counter: Option[Int])
extends Event(id)
final case class DeviceIdUpdated(override val id: Int, deviceId: Int) extends Event(id)
View setup.scala
private val tracerConfig = new Configuration(
config.getString("lora-server.jaeger.service-name"),
if (config.getBoolean("lora-server.jaeger.constant-sampling"))
new SamplerConfiguration("const", 1)
else new SamplerConfiguration(),
new ReporterConfiguration(
true, // logSpans
config.getString("lora-server.jaeger.agent-host"),
config.getInt("lora-server.jaeger.agent-port"),
config.getDuration("lora-server.jaeger.flush-interval").toMillis.toInt,
View ErrorHandlingFlow.scala
import akka.NotUsed
import akka.stream.scaladsl.Flow
case object NotZero
// Emits either an Int when zero, or a domain object indicating
// that the Int is non zero. Use this approach instead of relying
// on exceptions. Exceptions are for exceptional conditions,
// largely unanticipated, and they will terminate a stream.
val flow: Flow[Int, Either[NotZero.type, Int], NotUsed] =
@huntc
huntc / server.scala
Last active Dec 12, 2017
A complete server using Akka streams that reads some source, batches its data and then publishes. If the data cannot be published then it backs off with a best-effort of sending that data again.
View server.scala
val (recycleQueue, recycleSource) =
Source
.queue[SoilStateReading](100, OverflowStrategy.dropTail)
.prefixAndTail(0)
.map(_._2)
.toMat(Sink.head)(Keep.both)
.run()
StreamConverters.fromInputStream(() => this.getClass.getClassLoader.getResourceAsStream("sensors.log"))
.via(SoilStateReading.csvParser)
.merge(Source.fromFutureSource(recycleSource))
View gist:166b3e851c42743459ab2c876ce40668
### Keybase proof
I hereby claim:
* I am huntc on github.
* I am huntc (https://keybase.io/huntc) on keybase.
* I have a public key ASAK5MC9gaWxTBKWnZcUlTofK-51TIDi2R-UDtMGGUh_7Ao
To claim this, I am signing this object:
@huntc
huntc / mesos-salve.env
Last active Jul 13, 2016
MESOS environment variables
View mesos-salve.env
MESOS_AGENT_ENDPOINT=10.0.1.187:5051
MESOS_CHECKPOINT=0
MESOS_DIRECTORY=/tmp/mesos/slaves/e23ea3f5-0c2c-4220-8352-ec387538170f-S0/frameworks/e23ea3f5-0c2c-4220-8352-ec387538170f-0008/executors/conductr.node.christophersmbp.lan.executor/runs/3e175322-d045-41dc-975e-1f4394bffe68
MESOS_EXECUTOR_ID=conductr.node.christophersmbp.lan.executor
MESOS_EXECUTOR_SHUTDOWN_GRACE_PERIOD=5secs
MESOS_FRAMEWORK_ID=e23ea3f5-0c2c-4220-8352-ec387538170f-0008
MESOS_NATIVE_JAVA_LIBRARY=/usr/local/Cellar/mesos/0.28.1/lib/libmesos-0.28.1.dylib
MESOS_NATIVE_LIBRARY=/usr/local/Cellar/mesos/0.28.1/lib/libmesos-0.28.1.dylib
MESOS_SANDBOX=/tmp/mesos/slaves/e23ea3f5-0c2c-4220-8352-ec387538170f-S0/frameworks/e23ea3f5-0c2c-4220-8352-ec387538170f-0008/executors/conductr.node.christophersmbp.lan.executor/runs/3e175322-d045-41dc-975e-1f4394bffe68
MESOS_SLAVE_ID=e23ea3f5-0c2c-4220-8352-ec387538170f-S0
@huntc
huntc / esliteImpl.scala
Created Mar 10, 2016
Sample of using Scala with the Java DSL of Lagom
View esliteImpl.scala
package com.lightbend.conductr.eslite
import javax.inject.Named
import akka.NotUsed
import akka.actor.ActorRef
import akka.pattern.ask
import com.fasterxml.jackson.databind.node.ObjectNode
import com.google.inject.Inject
import com.lightbend.conductr.eslite.dto._
@huntc
huntc / SemVer.scala
Last active Mar 22, 2019
Semantic version case class
View SemVer.scala
import scala.util.Try
type PreRelease = Either[String, Int]
object SemVer {
val pattern = """^(\d+)\.(\d+)\.(\d+)(-(([1-9a-zA-Z][0-9a-zA-Z-]*)(\.([1-9a-zA-Z][0-9a-zA-Z-]*))))?$""".r
def apply(s: String): SemVer =
s match {
case pattern(major, minor, patch, _, _, preRelease1, _, preRelease2) =>
View Application.scala
def render(project: Project.Value, path: String) = EssentialAction { rh =>
val futureAction = project match {
case Project.ConductR =>
conductrDocRenderer.actorRef
.ask(DocRenderer.Render(path))(settings.doc.renderer.timeout)
.map {
case html: Html => Action(Ok(html))(rh)
case action: Action[AnyContent] => action(rh)
case DocRenderer.NotFound(p) => Action(NotFound(s"Cannot find $p"))(rh)
case DocRenderer.NotReady => Action(ServiceUnavailable("Initializing documentation. Please try again in a minute."))(rh)
View SourceInputStream.scala
/**
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.contrib.stream
import akka.actor.{ ActorRef, ActorRefFactory, FSM, Props }
import akka.pattern.ask
import akka.stream.actor.ActorSubscriberMessage.{ OnComplete, OnError, OnNext }
import akka.stream.actor.{ ActorSubscriber, RequestStrategy, ZeroRequestStrategy }
You can’t perform that action at this time.