Skip to content

Instantly share code, notes, and snippets.

@richdougherty
richdougherty / Hello.scala
Last active August 29, 2015 14:02
Trait-based implementation of JSON values
package com.example
object Hello {
def main(args: Array[String]): Unit = {
case class MyNumber(i: Int) extends JNumber {
def value = new java.math.BigDecimal(i)
}
println(matchJValue(MyNumber(23)))
}
package com.example
object Hello {
def main(args: Array[String]): Unit = {
case class MyNumber(i: Int) extends JNumber {
def value = new java.math.BigDecimal(i)
}
println(matchJValue(MyNumber(23)))
@richdougherty
richdougherty / JOption.scala
Last active August 29, 2015 14:02
An exploration of a generic JSON interface
/*
An exploration of a generic JSON interface.
TRAITS
Traits and extractor objects are used throughout, rather than case
classes, so that other implementations can encode JSON in different
ways. No constructors are provided for any of the JSON types. These
must be provided by implementations. Sealed traits are used so that
the compiler can still perform exhaustiveness checking.
@richdougherty
richdougherty / di.scala
Created July 8, 2014 05:28
Hashing out dependency injection for Play
trait Environment {
def config: Config
def rootPath: File
def classLoader: ClassLoader
def mode: Mode.Mode
}
trait ApplicationLoader {
def load(env: Environment): Application
}
case Http.IncomingConnection(remoteAddress, requestProducer, responseConsumer) ⇒
Flow(requestProducer).map { akkaHttpRequest =>
val tryApp = applicationProvider.get
val convertedRequestHeader = convertRequest(tryApp, remoteAddress, akkaHttpRequest)
val (taggedRequestHeader, handler) = getHandler(tryApp, convertedRequestHeader)
val responseProducer = executeHandler(
tryApp,
akkaHttpRequest,
taggedRequestHeader,

Keybase proof

I hereby claim:

  • I am richdougherty on github.
  • I am richdougherty (https://keybase.io/richdougherty) on keybase.
  • I have a public key whose fingerprint is CAF0 C24E D15C A212 2EC0 9C89 8CD9 5699 9692 9D60

To claim this, I am signing this object:

@richdougherty
richdougherty / play2_runner.py
Created August 17, 2014 19:56
Manual runner for TechEmpower Play2 tests
#!/usr/bin/env python
import collections, importlib, logging, os, setup_util, sys, time
# Run from the root TechEmpower dir with a command like:
# PYTHONPATH=toolset/setup/linux python play2_runner.py play2.setup_java
logging.basicConfig(level=logging.DEBUG)
setup_import = sys.argv[1]
@richdougherty
richdougherty / gist:e3ce5c47efd554e35c88
Created October 6, 2014 23:27
Initial Prune test results
Prune instance id is 9f438cb9-274a-4073-b00f-b7734ebe4ac1
Fetching Prune database records from remote
Pulling git@prune:playframework/prune.git [database] into /home/play/.prune/db and checking out database...
UP_TO_DATE
Pull done
Fetching Play source code from remote
Pulling https://github.com/playframework/playframework.git [master] into /home/play/.prune/play and checking out master...
UP_TO_DATE
Pull done
Fetching apps source code from remote
@richdougherty
richdougherty / prune-graph.html
Created October 8, 2014 14:16
Prune report graphing
<!doctype html>
<html lang="en">
<head>
<title>Prune results</title>
<script src="flot/jquery.js" charset="utf-8"></script>
<script src="flot/jquery.flot.js" charset="utf-8"></script>
<script src="flot/jquery.flot.time.js" charset="utf-8"></script>
<script src="jquery.flot.axislabels.js" charset="utf-8"></script>
<script src="report.js"></script>
<style>
trait Handler
// The most common top-level handler
trait RequestHandler extends Handler {
def executionContext: ExecutionContext
def handle(rh: RequestHeader): Handler
}
// For routers
trait PartialRequestHandler extends Handler {