Skip to content

Instantly share code, notes, and snippets.

View oxbowlakes's full-sized avatar

Christopher Marshall oxbowlakes

View GitHub Profile
import java.util.Optional;
import java.util.function.Function;
class Main {
public static void main(String[] args) {
Optional<String> o = Optional.of("foo");
Function<String, String> f = s -> null;
Function<String, String> g = String::valueOf;
//lawless lolz
2016-07-12 14:11:53,522 [104621160] ERROR - m.intellij.util.ExecutorsQuery - IntelliJ IDEA 2016.1.3 Build #IC-145.1617.8
2016-07-12 14:11:53,522 [104621160] ERROR - m.intellij.util.ExecutorsQuery - JDK: 1.8.0_45
2016-07-12 14:11:53,522 [104621160] ERROR - m.intellij.util.ExecutorsQuery - VM: Java HotSpot(TM) 64-Bit Server VM
2016-07-12 14:11:53,522 [104621160] ERROR - m.intellij.util.ExecutorsQuery - Vendor: Oracle Corporation
2016-07-12 14:11:53,522 [104621160] ERROR - m.intellij.util.ExecutorsQuery - OS: Windows 7
2016-07-12 14:11:53,522 [104621160] ERROR - m.intellij.util.ExecutorsQuery - Last Action: EditorEnter
2016-07-12 14:11:53,537 [104621175] ERROR - m.intellij.util.ExecutorsQuery - null
kotlin.KotlinNullPointerException
at org.jetbrains.kotlin.types.StarProjectionImplKt.starProjectionType(StarProjectionImpl.kt:48)
at org.jetbrains.kotlin.types.StarProjectionImpl$_type$2.invoke(StarProjectionImpl.kt:31)
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions for evaluation. Or try :help.
scala> import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.ExecutionContext.Implicits.global
scala> scala.concurrent.Future( { println("foo"); 4 })
foo
res0: scala.concurrent.Future[Int] = Success(4)

You have a single Java codebase in one repo to put all your code in. The code ultimately runs about 30 services/batch jobs (call these end points, or EPs). Some EPs share literally no code with others. All in all, we have well over 250 kloc compiled in one go to produce a single artefact (a jar, let's call it LEVIATHAN)

Each time a change is committed, the code is built and a new LEVIATHAN artefact version is emitted - hundreds of them, thousands even. There is a database where each EP is associated with the version of the code which should run it.

Stable EPs can thus be hundreds of versions behind current. Let's say that you need to update such a stable EP by adding some new feature. You are then in a position of having to bring EP "foobar" up from v1.2.3 of LEVIATHAN to v8.9.10. You have absolutely no idea whether code that Foobar depends on has changed problematically in this space.

I'm not in any way saying that this is a sensible way of organising a monorepo and I'm sure there are plenty of legitimat

class CsvUpdateParser(val header: String, val rows: Stream[String], val delimiter: String) extends CsvParser[(TxnId, ListedTransactionUpdateBuilder)] {
protected override def parse(line: String): Failure \/ (TxnId, ListedTransactionUpdateBuilder) = {
val cols = splitIgnoreQuotes(line, delimiter)
var a = 0
for {
txnId <- tokenAt("Txn ID", cols).map(_.toLong)
ccy <- tokenAt("Sett Ccy", cols).map(parseCcy)
rate <- tokenAt("Sett FX", cols).map(parseBigDecimal)
settDate <- tokenAt("Sett Date", cols).map(x => parseAccountingDate(x, "yyyy-MM-dd"))
state <- tokenAt("State", cols).map(x => if (x.isEmpty) null else EventState.valueOf(x))
Error:(117, 26) type mismatch;
found : akka.http.scaladsl.server.Route
(which expands to) akka.http.scaladsl.server.RequestContext => scala.concurrent.Future[akka.http.scaladsl.server.RouteResult]
required: akka.stream.scaladsl.Flow[akka.http.scaladsl.model.HttpRequest,akka.http.scaladsl.model.HttpResponse,Any]
Http().bindAndHandle(route, thisHost, port) onComplete {
//where:
val route: Route = ???

In this page of the Spray migration guide, we are told that marshalling a response looks like this:


Marshaller.of can be replaced with Marshaller.withFixedContentType.

Was:

Marshaller.of[JsonApiObject](`application/json`) { (value, contentType, ctx) =>

ctx.marshalTo(HttpEntity(contentType, value.toJson.toString))

I spent a lot of time tryig to understand why, when I appeared to be following the minimal example from the akka HTTP server documentation, scalac was refusing to compile my code.

Here is the minimal example in its entirety:

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer

import scala.io.StdIn

// Does the Java memory model guarantee that this program will *always* print
// x=1 and y=2
//
//Or might the JVM decide that the changes made to x and y in t2 do not need to be visible from t1 because neither x nor
// y is volatile and nor are they modified within a sychronized block (or within the confines of a j.u.c Lock)?
// i.e. I am unsure whether you can observe
// x=0 and y=0
//
//I believe that the memory model *definitely makes the guarantee* that t1 will *never* print something like:
object EquationalReasoningBreakdown extends SafeApp {
import scalaz.effect._
def parse(ioa: IO[String]): IO[Int] =
ioa
.flatMap { s =>
IO(s.toInt)
}
.except { case NonFatal(_) =>
IO(-1)