Skip to content

Instantly share code, notes, and snippets.

View schleichardt's full-sized avatar

Michael Schleichardt schleichardt

  • eHealth Experts GmbH
View GitHub Profile
@fehmicansaglam
fehmicansaglam / Application.java
Created February 9, 2012 18:50
Accept range header and write a partial content to the response with Play! Framework.
public static void downloadFile(final Long fileId) throws IOException {
response.setHeader("Accept-Ranges", "bytes");
notFoundIfNull(fileId);
File underlyingFile = ... //load file
String fileName = ...//name of the file
Header rangeHeader = request.headers.get("range");
if (rangeHeader != null) {
throw new PartialContent(underlyingFile, fileName);
@dragos
dragos / gist:1794246
Created February 11, 2012 00:01
A Scala compiler plugin that creates a new class in a different (fresh) package
package scala.plugin
import scala.tools.nsc
import nsc.Global
import nsc.Phase
import nsc.plugins.Plugin
import nsc.plugins.PluginComponent
import nsc.transform.{ Transform, TypingTransformers }
import nsc.symtab.Flags
import scala.tools.nsc.transform.TypingTransformers
@guillaumebort
guillaumebort / Secured.scala
Created April 7, 2012 12:05
HTTP Basic Authorization for Play 2.0
def Secured[A](username: String, password: String)(action: Action[A]) = Action(action.parser) { request =>
request.headers.get("Authorization").flatMap { authorization =>
authorization.split(" ").drop(1).headOption.filter { encoded =>
new String(org.apache.commons.codec.binary.Base64.decodeBase64(encoded.getBytes)).split(":").toList match {
case u :: p :: Nil if u == username && password == p => true
case _ => false
}
}.map(_ => action(request))
}.getOrElse {
Unauthorized.withHeaders("WWW-Authenticate" -> """Basic realm="Secured"""")
@sadache
sadache / AA.md
Created July 8, 2012 21:29
Is socket.push(bytes) all you need to program Realtime Web apps?

Is socket.push(bytes) all you need to program Realtime Web apps?

One of the goals of Play2 architecture is to provide a programming model for what is called Realtime Web Applications.

Realtime Web Applications

Realtime Web Applications are applications that make use of Websockets, Server Sent Events, Comet or other protocols offering/simulating an open socket between the browser and the server for continuous communication. Basically, these applications let users work with information as it is published - without having to periodically ping the service.

There are quite a few web frameworks that target the development of this type of application: but usually the solution is to simply provide an API that allows developers to push/receive messages from/to an open channel, something like: