Skip to content

Instantly share code, notes, and snippets.

View jroper's full-sized avatar

James Roper jroper

View GitHub Profile
@jroper
jroper / With Grzegorz's improvements
Last active December 21, 2015 22:19
Scala incremental compiler improvements by Grzegorz Kossakowski. Actual runtimes are not so important here, since the two benchmarks were run on different machines, and also they make no attempt to ensure that the scala compiler is fully JITed, which during normal Play development offers significant improvements over these times as the compiler …
Initial clean compile of entire project:
[info] [info] Compiling 29 Scala sources and 1 Java source to /tmp/inc-compile/target/scala-2.10/classes...
[info] [success] Total time: 15 s, completed Aug 28, 2013 9:43:38 PM
Now simulate adding a method to a controller:
[info] [info] Compiling 1 Scala source to /tmp/inc-compile/target/scala-2.10/classes...
[info] [success] Total time: 2 s, completed Aug 28, 2013 9:43:40 PM
Now simulate adding a new route to the routes file:
[info] [info] Compiling 2 Scala sources and 1 Java source to /tmp/inc-compile/target/scala-2.10/classes...
@jroper
jroper / Global.scala
Last active December 20, 2015 19:38
Transparent HEAD request handling in Play 2.1. Note that it may be more efficient to implement HEAD support in an action directly, as this may avoid unnecessary opening of resources or rendering things.
import play.api.libs.iteratee.{Done, Iteratee, Enumerator}
import play.api.mvc._
import play.api._
import play.api.libs.concurrent.Execution.Implicits._
object Global extends GlobalSettings {
override def onRouteRequest(req: RequestHeader) = {
// Lookup handler
super.onRouteRequest(req) match {
@jroper
jroper / MyManagedResource.scala
Last active November 4, 2021 10:20
Play resource routing
class MyManagedResource extends ResourceController[String] {
def index = Action(Ok("index"))
def newScreen = Action(Ok("new"))
def create = Action {
Redirect(MyInjectableResource.reverseRoutes.index())
}
def show(id: String) = Action(Ok("Show " + id))
@jroper
jroper / HttpPipeliningChannel.java
Last active December 15, 2015 06:59
Demonstration of HTTP pipelining support in Netty.
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.*;
import org.jboss.netty.handler.codec.http.*;
import java.net.SocketAddress;
import java.util.LinkedList;
import java.util.concurrent.Callable;
public class HttpPipeliningHandler implements ChannelUpstreamHandler, ChannelDownstreamHandler {
@jroper
jroper / Ec2Client.scala
Created February 26, 2013 19:44
Barebones Ec2 client that uses the Play Framework WS API for provisioning instances. Handles authentication signing etc. If you want to use it, you probably want to read the docs: http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-RunInstances.html and update it to do what you need it to do.
package utils
import scala.xml.Elem
import scala.concurrent.Future
import java.util.{TimeZone, Date}
import java.text.SimpleDateFormat
import java.net.URLEncoder
import javax.crypto.spec.SecretKeySpec
import javax.crypto.Mac
import org.apache.commons.codec.binary.Base64
@jroper
jroper / TestController.scala
Created November 15, 2012 06:56
Compile errors with Json reads/writes
package controllers
import play.api.mvc.{Cookie, Action, Controller}
import play.api.libs.json._
import org.apache.commons.codec.binary.Base64
import play.api.libs.json.JsString
import play.api.data.validation.ValidationError
/**
* Used for testing stuff.
@jroper
jroper / EbeanShutdownHack.java
Created November 8, 2012 01:28
Ebean shutdown hack, for shutting down an individual ebeanserver before the Ebean shutdown hook runs
package com.avaje.ebeaninternal.server.lib;
import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Exists to work around this issue:
*
@jroper
jroper / child.threaddump
Created October 6, 2012 04:26
Thread dumps of hung play builds
2012-10-06 14:18:46
Full thread dump Java HotSpot(TM) 64-Bit Server VM (20.10-b01-428 mixed mode):
"DestroyJavaVM" prio=5 tid=7f8444003000 nid=0x10472b000 waiting on condition [00000000]
java.lang.Thread.State: RUNNABLE
"com.google.common.base.internal.Finalizer" daemon prio=5 tid=7f844bdd7000 nid=0x10e4ab000 in Object.wait() [10e4aa000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <7f40c3a90> (a java.lang.ref.ReferenceQueue$Lock)
@jroper
jroper / playlighthouselinker.js
Created September 21, 2012 06:47
Play Lighthouse Linker Greasemonkey Script
// ==UserScript==
// @name Play 2 Lighthouse Linker
// @description Links Play 2 Lighthouse ticket references to lighthouse
// @namespace http://playframework.org
// @version 1.0
// @author James Roper <james@jazzy.id.au>
// @include https://github.com/playframework/Play20/*
// @require http://code.jquery.com/jquery-1.8.2.min.js
// @run-at document-end
// ==/UserScript==
@jroper
jroper / gist:3034154
Created July 2, 2012 16:38
Play sessions
running(fakeApplication(), new Runnable() {
@Override
public void run() {
FakeRequest req = fakeRequest();
for (int i = 0; i < 5; i++) {
req = req.withSession("key" + i, "value" + i);
}
for (int i = 0; i < 5; i++) {
if (!req.getWrappedRequest().session().get("key" + i).isDefined()) {
// Whether we reach this point or not depends on HashMap ordering