This file contains hidden or 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 toBytesWritable(p: Pipe, f: Fields): Pipe = { | |
import Dsl._ // Make sure we have the scalding DSL in scope: | |
import Fields | |
asList(f).foldLeft(p) { (oldPipe, fld) => | |
oldPipe.map(fld -> fld) { str: String => new ImmutableBytesWritable(str.getBytes) } | |
} | |
} | |
// Now call: |
This file contains hidden or 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
supervisor1 { | |
akka { | |
actor { | |
provider = "akka.remote.RemoteActorRefProvider" | |
} | |
remote { | |
enabled-transports = ["akka.remote.netty.tcp"] | |
netty.tcp { | |
hostname = "0.0.0.0" | |
port = 2554 |
This file contains hidden or 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
// Run with | |
// unflatten -l 7 ritchieboykin.gv | dot -Tpng -o ritchieboykin.png && open ritchieboykin.png | |
digraph RitchieBoykin { | |
page = "8.2677165,11.692913"; | |
overlap=false; | |
ratio = "auto"; | |
mincross = 2.0; | |
graph [style="filled, rounded", color=lightgrey, fillcolor=khaki, fontsize=10]; | |
subgraph cluster_0 { |
This file contains hidden or 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
// Taken from: http://jnordenberg.blogspot.com/2008/08/hlist-in-scala.html | |
object HListTest { | |
sealed trait HList | |
final class HNil extends HList { | |
def ::[T](v : T) = HCons(v, this) | |
} | |
val HNil = new HNil() |
This file contains hidden or 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 org.apache.log4j.Logger | |
sealed trait LogLevel | |
case object Info extends LogLevel | |
case object Warn extends LogLevel | |
case object Error extends LogLevel | |
sealed trait Logged[T] { | |
def map[U](fn: T => U): Logged[U] |
This file contains hidden or 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
// could easily be ported to Scala Future | |
import com.twitter.util.{Promise, Future} | |
trait Source[+T] { self => | |
def head: Option[T] | |
def tail: Future[Source[T]] | |
def map[U](fn: T => U): Source[U] = new Source[U] { | |
def head = self.head.map(fn) | |
def tail = self.tail.map { _.map(fn) } | |
} |
This file contains hidden or 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
[info] Loading project definition from /Users/oscarb/workspace/chill/project | |
[info] Compiling 1 Scala source to /Users/oscarb/workspace/chill/project/target/scala-2.9.2/sbt-0.12/classes... | |
[info] Set current project to chill-all (in build file:/Users/oscarb/workspace/chill/) | |
[info] Updating {file:/Users/oscarb/workspace/chill/}chill-all... | |
[info] Updating {file:/Users/oscarb/workspace/chill/}chill-java... | |
[info] Resolving org.scala-tools.testing#specs_2.9.3;1.6.9 ... | |
[info] downloading http://oss.sonatype.org/content/repositories/releases/org/scalacheck/scalacheck_2.9.3/1.10.0/scalacheck_2.9.3-1.10.0-sources.jar ... | |
[info] [SUCCESSFUL ] org.scalacheck#scalacheck_2.9.3;1.10.0!scalacheck_2.9.3.jar(src) (1248ms) | |
[info] downloading http://oss.sonatype.org/content/repositories/releases/org/scala-tools/testing/specs_2.9.3/1.6.9/specs_2.9.3-1.6.9-sources.jar ... | |
[info] [SUCCESSFUL ] org.scala-tools.testing#specs_2.9.3;1.6.9!specs_2.9.3.jar(src) (1838ms) |
This file contains hidden or 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 WriteOnce[T] { | |
private val ref = new java.util.concurrent.atomic.AtomicReference[Option[T]](None) | |
def init(t: T) { if(!ref.compareAndSet(None, Some(t))) sys.error("Already written"); } | |
def get: Option[T] = ref.get | |
} | |
scala> val w = new WriteOnce[Int] | |
w: WriteOnce[Int] = WriteOnce@215d55cb | |
scala> w.get |
This file contains hidden or 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
/** | |
scala> compress(List.fill(1000)(1)) | |
res17: List[Either[Int,Int]] = List(Left(1), Right(0), Left(1), Right(1), Left(1), Right(2), Left(1), Right(3), Left(1), Right(4), Left(1), Right(5), Left(1), Right(6), Left(1), Right(7), Left(1), Right(8), Left(1), Right(9), Left(1), Right(10), Left(1), Right(11), Left(1), Right(12), Left(1), Right(13), Left(1), Right(14), Left(1), Right(15), Left(1), Right(16), Left(1), Right(17), Left(1), Right(18), Left(1), Right(19), Left(1), Right(20), Left(1), Right(21), Left(1), Right(22), Left(1), Right(23), Left(1), Right(24), Left(1), Right(25), Left(1), Right(26), Left(1), Right(27), Left(1), Right(28), Left(1), Right(29), Left(1), Right(30), Left(1), Right(31), Left(1), Right(32), Left(1), Right(33), Left(1), Right(34), Left(1), Right(35), Left(1), Right(36), Left(1), Right(37), Left(1), Ri... | |
scala> compress(List.fill(1000)(1)).size | |
res18: Int = 88 | |
scala> decompress(res17) | |
res19: List[Int] = List(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
This file contains hidden or 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
scala> class PostFix[A](a: A) { | |
| def |>[B](fn: A => B): B = fn(a) | |
| } | |
defined class PostFix | |
scala> implicit def toPf[A](a: A) = new PostFix(a) | |
toPf: [A](a: A)PostFix[A] | |
scala> val inc = { x: Int => x + 42 } | |
inc: Int => Int = <function1> |