Skip to content

Instantly share code, notes, and snippets.

View jboner's full-sized avatar

Jonas Bonér jboner

View GitHub Profile
@derekjw
derekjw / akka-future-pi.scala
Created April 10, 2011 22:14
Alternate implementations of Akka's Pi Tutorial
import scalaz._,Scalaz._
import akka.scalaz.futures._
import akka.dispatch._
import System.{currentTimeMillis => now}
object Pi extends App {
val nrOfElements = 10000
val nrOfMessages = 10000
trait Constructable[T] {
def construct: T
}
implicit object IntIsConstructable extends Constructable[Int] {
def construct = 42
}
implicit object StringIsConstructable extends Constructable[String] {
def construct = "Hello World"
@oxbowlakes
oxbowlakes / ScalaSolarizedDark.xml
Created June 20, 2011 13:13
ScalaSolarizedDark.xml
<?xml version="1.0" encoding="UTF-8"?>
<scheme name="OxbowSolarizedDark" version="1" parent_scheme="Default">
<option name="LINE_SPACING" value="1.2" />
<option name="EDITOR_FONT_SIZE" value="13" />
<option name="EDITOR_FONT_NAME" value="Consolas" />
<colors>
<option name="ADDED_LINES_COLOR" value="" />
<option name="ANNOTATIONS_COLOR" value="2b36" />
<option name="ANNOTATIONS_MERGED_COLOR" value="" />
<option name="CARET_COLOR" value="dc322f" />
@havocp
havocp / OpenSourceLab.md
Created August 31, 2011 16:48
Dreamforce Open Source Lab

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

@bdarfler
bdarfler / microbenchmark-runner.scala
Created September 8, 2011 15:27
Scala Microbenchmark Runner
def benchmark(runs: Long, reps: Long, funct: => Any) = {
// warmup
println("Warming Up")
var i = 0
while ( i < 25000 ) { funct; i = i + 1 }
// test runs
println("Running Test")
var j = 0
while ( j < runs ) {
var k = 0
anonymous
anonymous / overtone-1.clj
Created December 6, 2011 05:04
(ns test.core
(:use [overtone.live]
[overtone.inst.synth]))
(def kick (sample "kick.wav"))
(def snare (sample "snare.wav"))
(def hit (sample "hit.wav"))
(def insts {:kick kick
:snare snare
:hit hit})
@daggerrz
daggerrz / CircuitBreakingDispatcherSemantics
Created January 24, 2012 15:04
Akka 1.3 circuit breaking dispatcher
package com.tapad.util
import akka.dispatch._
import java.util.concurrent.atomic.{AtomicInteger, AtomicBoolean}
class LogAndDiscardCircuitBreakerPolicy(val maxMailboxSize: Int, loggable: Logging) extends CircuitBreakerPolicy {
def onOverflowStart(mailboxSize: Int) { loggable.log.warn("Mailbox size is above {}. Ignoring messages until size is back below.", maxMailboxSize) }
def onBackToNormal(overflowCount: Int) { loggable.log.info("Mailbox size is back below {}. A total of {} messags were discarded.", maxMailboxSize, overflowCount) }
def replyToOverflow(overflowCount: Int, msg: Any) : Either[Exception, Any] = Left(new IllegalArgumentException("This overflow policy is not configured for request-reply actors."))
@henrikengstrom
henrikengstrom / gist:1843428
Created February 16, 2012 08:50
Akka2.0-RC1 example of using futures to re-start long running task
import akka.actor.{ Props, ActorSystem, Actor }
import akka.pattern.ask
import akka.util.Timeout
import akka.util.duration._
import akka.dispatch.Await
import util.Random
object DangerousOpTest extends App {
println("starting system")
val system = ActorSystem("daOp")
@chrsan
chrsan / AkkaUnfilteredSample.scala
Created February 17, 2012 09:47
Akka 2.0 unfiltered RESTful sample
package akka.unfiltered
import akka.actor._
import akka.dispatch.Future
import akka.pattern.ask
import akka.util.duration._
import akka.util.Timeout
import unfiltered.Async
import unfiltered.request._
@marnix
marnix / scala-di-from-comment-7789930.scala
Created March 2, 2012 06:27
This code is a copy (roughly reconstructed from reformatted and reordered parts in an abandoned Eclipse project) of the code that was originally in http://jonasboner.com/2008/10/06/real-world-scala-dependency-injection-di.html#comment-7789930.
trait BeeperDevice {
def beep(beepSound: String)
}
trait DependsOnBeeper {
protected val beeper: BeeperDevice
}
class Beeper extends BeeperDevice {