This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object MyController extends Controller with StrictLogging { | |
def index = | |
AdminAction.async { implicit request => | |
request.method match { | |
case "GET" => | |
Future.successful(Ok("GET")) | |
case "POST" => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Main extends testing.Benchmark { | |
val r = """[\r\n\s]""".r | |
val s = """ | |
| Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod | |
| tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim | |
| veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea | |
| commodo consequat. Duis aute irure dolor in reprehenderit in voluptate | |
| velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code won't compile without some Play dependencies being satisfied. | |
// Like Controller, formats.parsing, etc. It's just for reference. | |
object ArticlesController extends Controller { | |
import java.util.Locale | |
// Our application has several translations for an Article: | |
val locales: List[Locale] = Seq(Locale.US, Locale.JAPAN) | |
def create = Action { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def resize(current: Long, target: Long, iteration: Long = 1): Unit = { | |
val step = Math.max(current - (current / 7), target) | |
printf("[%04d] RESIZE FROM %d TO %d\n", iteration, current, step) | |
if(step > target) | |
resize(step, target, iteration + 1) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.Future | |
val a = Future { 1 } // completes immediately. | |
val b = Future { Thread.sleep(1000); 2 } // is the last to complete. | |
val c = Future { Thread.sleep(100); 3 } // completes after 1 but before 2. | |
Future.sequence(Seq(a, b, c)) map println | |
// > List(1, 2, 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The TestKit class is just: | |
class TestKit(_system: ActorSystem) extends { implicit val system = _system } with TestKitBase | |
// TestKitBase uses `system` in it's constructor so _it must be defined before extending TestKitBase_! | |
// You can't use `this` within alternate constructors however, so the solution isn't as easy as: | |
class MySpec extends TestKit(ActorSystem(this.getClass.getSimpleName)) | |
// So let's ignore `TestKit` and focus on `TestKitBase`. That way we can have our own constructors that execute before | |
// TestKitBase's constructor. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor._ | |
object Scraper { | |
def props = Props[Scraper] | |
} | |
class Scraper extends Actor with ActorLogging with Unhandled { | |
import MigrationProtocol._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Parser { self: Actor => | |
def parse: PartialFunction[Opened, Unit] | |
def receive: Receive = parse orElse(super.receive) andThen(_ => done()) | |
def collectWork: Receive | |
def done(): Unit = { | |
context become collectWork |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Job extends Actor { | |
def receive = idle | |
def idle: Receive = { | |
case Parse(_uri) => | |
uri = _uri | |
requestor = context.sender() | |
sources ! Open(_uri) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
brew install redis | |
redis-cli hset services resque '["localhost"]' | |
jgem install rack -v1.3.6 | |
jgem install jruby-rack -v1.1.1 | |
jgem install trinidad -v1.2.3 | |
git clone git://github.com/sam/geminaboxplus.git | |
cd geminaboxplus | |
bundle install --path vendor | |
rake resque:work & | |
GEMINABOX_DATA="$(pwd)/data" jruby -S trinidad |