Skip to content

Instantly share code, notes, and snippets.

View andyczerwonka's full-sized avatar

Andy Czerwonka andyczerwonka

View GitHub Profile
@andyczerwonka
andyczerwonka / gist:4447120
Last active December 10, 2015 14:19
I'm trying to serve an image from Play, where the image originates from Gravatar. This code doesn't seem to work, but the URL is correct.
import play.api._
import play.api.mvc._
import play.api.libs.ws.WS
import play.api.libs.concurrent.Execution.Implicits._
import java.io.File
object Application extends Controller {
def index(email: String) = Action {
Async {
@andyczerwonka
andyczerwonka / measures.scala
Created May 22, 2012 19:34
I'm trying to understand how to best deal with sending an async request to a web service
def measures(user: User): List[Measure] = {
val prefs = UserPreferences.findByUser(user) // get my prefs
val request = generateRequest(prefs) // build up a WS request
val promise = WS.url(exportEndpoint).post(request)
promise.orTimeout(Nil, 100000).map { responseOrTimeout =>
responseOrTimeout.fold(
response => {
val body = promise.value.get.body
val lines = body.split("\n").map(_.split(","))
lines.map {
@andyczerwonka
andyczerwonka / Controller.scala
Created May 10, 2012 23:25
Code that is trying illustrate my LinkageError
def dashboard = Action {
val user = User.findByUsername("aczerwonka")
val prefs = UserPreferences.findByUsername("aczerwonka")
val config = Configuration.get();
Ok(views.html.dashboard(user, prefs, config))
}
@andyczerwonka
andyczerwonka / Configuration.scala
Created May 9, 2012 18:05
Specs2 test for parsing JSON and extracting into a case class
package models
case class ProductionType(
key: String,
name: String,
blended: Boolean,
forecast: Boolean,
actual: Boolean,
field: Boolean,
financial: Boolean,
@andyczerwonka
andyczerwonka / euler11.scala
Created April 28, 2011 20:14
The answer to Project Euler #11, using the Scala Actor library
package euler
import scala.actors.Actor
import Actor._
object Euler011 extends Actor {
type Matrix = Seq[Seq[Int]]
case class CalculateMaxRequest(matrix: Matrix, from: Actor)
case class CalculateMaxReply(matrix: Matrix, max: Int)