Skip to content

Instantly share code, notes, and snippets.

View oxbowlakes's full-sized avatar

Christopher Marshall oxbowlakes

View GitHub Profile
@oxbowlakes
oxbowlakes / oxbow.xml
Created June 20, 2011 09:32
IntelliJ IDEA color scheme for Scala/Java
<?xml version="1.0" encoding="UTF-8"?>
<scheme name="oxbow" version="1" parent_scheme="Default">
<option name="LINE_SPACING" value="1.0" />
<option name="EDITOR_FONT_SIZE" value="12" />
<option name="EDITOR_FONT_NAME" value="Consolas" />
<colors />
<attributes>
<option name="ABSTRACT_CLASS_NAME_ATTRIBUTES">
<value>
<option name="FOREGROUND" value="666666" />
@oxbowlakes
oxbowlakes / ZioTransactions.scala
Created October 10, 2018 11:37
Using scalaz ZIO to provide a transactional database commit
import java.sql.{Connection, SQLException}
import javax.sql.DataSource
import scalaz.zio.{IO, KleisliIO}
object Transactions {
sealed abstract class Isolation(private[Transactions] val i: Int)
object Isolation {
case object Serialized
@oxbowlakes
oxbowlakes / gist:1869377
Created February 20, 2012 14:06
Simple scala collection examples
scala> (1 to 20).toList
res1: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
//Simple side effects
scala> res1 take 3 foreach (i => println(i))
1
2
3
scala> res1 take 3 foreach println
@oxbowlakes
oxbowlakes / 3nightclubs.scala
Created May 13, 2011 15:14
A Tale of 3 Nightclubs
/**
* Part Zero : 10:15 Saturday Night
*
* (In which we will see how to let the type system help you handle failure)...
*
* First let's define a domain. (All the following requires scala 2.9.x and scalaz 6.0)
*/
import scalaz._
import Scalaz._
@oxbowlakes
oxbowlakes / scala_java_enums.scala
Created November 30, 2018 14:40
Incorrect scalac warnings on aliased java enum
Welcome to Scala 2.12.3 (OpenJDK 64-Bit Server VM, Java 1.8.0_181).
Type in expressions for evaluation. Or try :help.
scala> :paste
// Entering paste mode (ctrl-D to finish)
type TU = java.util.concurrent.TimeUnit
val NANOSECONDS: TU = java.util.concurrent.TimeUnit.NANOSECONDS
val MICROSECONDS: TU = java.util.concurrent.TimeUnit.MICROSECONDS
val MILLISECONDS: TU = java.util.concurrent.TimeUnit.MILLISECONDS

Description of Program

I have a program which looks roughly like this

  1. Waits for some files
  2. When they arrive, parses them to extract data
  3. Reads database state
  4. Performs calculation
  5. Saves new state to database
  6. Generates emails on the basis of computed data

WTF is going on?

Don't let anyone mislead you that there are no big changes. The big change is that fixes and security updates will no longer be provided to old versions of Java unless:

  1. You are a paying customer, in which case Oracle will be patching 8 years' worth of LTS versions, as well as the current version
  2. The community backports these fixes to OpenJDK and makes them available

Step back a bit. What is OpenJDK and what does LTS mean?

Historically OpenJDK was quite separate from OracleJDK. This is no longer the case. Oracle are basically providing two separate distributions of Java: OracleJDK and OpenJDK. They are meant to be technically equivalent, although it should be pretty obvious that OracleJDK is likely to ship with add-on features aimed at enterprises (e.g. management tooling or better GC).

@oxbowlakes
oxbowlakes / concurrency.java
Last active May 11, 2018 08:54
Concurrency interview question
///////////////////////////////////////////////////////////////////////
// You are supplied with the following interfaces/implementations
///////////////////////////////////////////////////////////////////////
/** Interface representing the performing of a computation at some specific key */
public interface Computation<K, V> {
K key();
V compute();
}
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 scalaz 8 IO
IO.fail(new Error("1"))
.ensuring(IO.fail(new Error("2")))
.ensuring(IO.fail(new Error("3")))
.catchAll[E](e4 => IO.sync(println(e4.toString)))
//is (I think) equivalent to this?
try {
try {
try {