Skip to content

Instantly share code, notes, and snippets.

@havocp
havocp / Config.scala
Created May 28, 2012
sketchy config scala wrapper
View Config.scala
package scala.config
import scala.config._
import com.typesafe.{ config => j }
sealed trait ConfigMergeable {
def asJava: j.ConfigMergeable
def withFallback(mergeable: ConfigMergeable): ConfigMergeable
}
@havocp
havocp / actor-mixins-mapbehavior.patch
Created May 18, 2012
Squashed patch with mapBehavior
View actor-mixins-mapbehavior.patch
diff --git a/akka-actor-tests/src/test/java/akka/actor/JavaAPI.java b/akka-actor-tests/src/test/java/akka/actor/JavaAPI.java
index 5125611..25268dd 100644
--- a/akka-actor-tests/src/test/java/akka/actor/JavaAPI.java
+++ b/akka-actor-tests/src/test/java/akka/actor/JavaAPI.java
@@ -8,6 +8,10 @@ import akka.routing.CurrentRoutees;
import akka.routing.FromConfig;
import akka.routing.NoRouter;
import akka.testkit.AkkaSpec;
+import static akka.pattern.Patterns.ask;
+import akka.dispatch.*;
@havocp
havocp / binding.scala
Created May 10, 2012
Binding implicits
View binding.scala
trait CacheContext
trait Cache {
def lookup(query: String)(implicit context: CacheContext): String
def store(id: String, value: String)(implicit context: CacheContext): Unit
}
class BoundCache(private val delegate: Cache)(implicit private val context: CacheContext) {
def lookup(query: String): String =
delegate.lookup(query)
@havocp
havocp / common-package.scala
Created May 8, 2012
Play result composition
View common-package.scala
/* Caution: untested code. Allows composing Result objects in Play 2.0 */
import play.api.mvc._
import play.api.http.HeaderNames
package object common {
def mapPlain(result: Result, f: PlainResult => Result): Result = {
result match {
@havocp
havocp / dispatch-tasks.patch
Created May 2, 2012
don't batch tasks across executors, and consolidate some closures and Runnables into one Task object
View dispatch-tasks.patch
diff --git a/src/library/scala/concurrent/impl/Future.scala b/src/library/scala/concurrent/impl/Future.scala
index 957f9cf..0dcfa87 100644
--- a/src/library/scala/concurrent/impl/Future.scala
+++ b/src/library/scala/concurrent/impl/Future.scala
@@ -44,13 +44,11 @@ private[concurrent] object Future {
}
def boxedType(c: Class[_]): Class[_] = if (c.isPrimitive) toBoxed(c) else c
-
- def apply[T](body: =>T)(implicit executor: ExecutionContext): Future[T] = {
@havocp
havocp / future-bound-to-context.patch
Created May 2, 2012
Support binding a future to an ExecutionContext for Java
View future-bound-to-context.patch
diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala
index bd58b3a..b218bf8 100644
--- a/src/library/scala/concurrent/Future.scala
+++ b/src/library/scala/concurrent/Future.scala
@@ -534,6 +534,25 @@ trait Future[+T] extends Awaitable[T] {
p.future
}
+ /**
+ * Obtain a `scala.concurrent.FutureWithExecutionContext` where
@havocp
havocp / SafeActor.scala
Created Apr 23, 2012
Use actor state from Future callbacks
View SafeActor.scala
package com.ometer.akka
import akka.actor.Actor
import akka.dispatch.ExecutionContext
import akka.actor.ActorRef
import akka.dispatch.Promise
import akka.dispatch.Future
import akka.dispatch.DefaultPromise
class Example extends SafeActor {
@havocp
havocp / EnhancedURI.scala
Created Apr 5, 2012
Lame URI manipulation
View EnhancedURI.scala
/**
* Copyright (C) 2012 Typesafe, Inc <http://typesafe.com>
*/
import java.net.URI
import java.net.URLDecoder
import java.net.URLEncoder
object EnhancedURI {
implicit def uri2enhanced(uri: URI) = new EnhancedURI(uri)
}
@havocp
havocp / HelpAndLint.scala
Created Dec 17, 2011
Hacky build-lint and new-help commands
View HelpAndLint.scala
package com.typesafe.sbthelp
import _root_.sbt._
import Project.Initialize
import Keys._
import Defaults._
import Scope.GlobalScope
import Load.BuildStructure
import scala.annotation.tailrec
@havocp
havocp / OpenSourceLab.md
Created Aug 31, 2011
Dreamforce Open Source Lab
View OpenSourceLab.md

This quickstart will get you going with Scala and the twitter-finagle web library on the Cedar stack. Prerequisites

  • Basic Scala knowledge, including an installed version of sbt 0.10.x and a JVM.
  • Basic Git knowledge, including an installed version of Git.
  • Your application must be compatible with sbt 0.10.1 or higher and scala 2.8.1.
  • Your application must run on the OpenJDK version 6.
  • An installed version of Ruby.

Install the Heroku Command-line Client