Skip to content

Instantly share code, notes, and snippets.

@softprops
softprops / build.sbt
Created November 27, 2011 05:35
unfiltered embedded jetty
libraryDependencies += Seq(
"net.databinder" %% "unfiltered-filter" % "0.5.1",
"net.databinder" %% "unfiltered-jetty" % "0.5.1",
)
@casualjim
casualjim / actor_specification.scala
Created November 30, 2011 13:42
Specs2 with Akka and jodatime support
trait ActorSpecification extends BaseSpecification
with ArgumentsArgs
with ArgumentsShortcuts
with MustThrownMatchers
with ShouldThrownMatchers
with FormattingFragments
with StandardResults
with StandardMatchResults
with PendingUntilFixed
with TimeHelpers
@etorreborre
etorreborre / PragmaticIoSpec.scala
Created December 5, 2011 23:22
Scalaz different behaviors when traversing a Stream/Seq with Option/IO and folding left or right.
"traverse left with Stream and IO" >> {
implicit def traverseImplicit = StreamLeftTraverse
var result: Seq[Int] = Seq()
val f = (i: Int) => (result = result :+ i).pure[IO]
(1 to 3).toStream.map(f).sequence.unsafePerformIO
result must_== Seq(3, 2, 1)
}
"traverse right with Stream and IO" >> {
@bhudgeons
bhudgeons / AggregationFrameworkTest.scala
Created February 21, 2012 16:24
MongoDB Aggregation Framework Via Casbah
import com.mongodb.casbah.Imports._
/*
* Simple test of the MongoDB Aggregation Framework via Casbah
*
* [Note: only works on MongoDB 2.1+]
*
* The "students" collection consists of student test score records that [simplified] look like this:
*
{
@viktorklang
viktorklang / swingactors.scala
Created April 19, 2012 17:25
Swing Actors using Akka
// ©2012 Viktor Klang
package akka.klang
import akka.dispatch.{ DispatcherPrerequisites, ExecutorServiceFactory, ExecutorServiceConfigurator }
import com.typesafe.config.Config
import java.util.concurrent.{ ExecutorService, AbstractExecutorService, ThreadFactory, TimeUnit }
import java.util.Collections
import javax.swing.SwingUtilities
@kiritsuku
kiritsuku / Othello.scala
Last active October 3, 2015 14:48
Othello/Reversi implementation in Scala
import scala.util.parsing.combinator.JavaTokenParsers
import scala.util.Try
/*
* Compiles only with 2.10
*/
object Othello extends App with InputHandler {
private[this] var game = Game.empty
@stonegao
stonegao / gist:2657252
Created May 11, 2012 03:06 — forked from mardambey/gist:2654382
Reset Kafka offsets in ZooKeeper by deleting the corresponding nodes.
/**
* Notes: This code uses AsyncValue[T], a custom class that uses actors
* to allow concurrent operations on the provided type. It can be replaced
* by an Atomic object from the java.util.concurrent package or something
* that provides similar functionality.
*/
/**
* Resets the offsets for the given group / topic pair.
@pedrofurla
pedrofurla / snippet.scala
Created May 12, 2012 03:51
Side-effect free handling of exceptions.The three first expressions can throw something
def exp[T](t: => T) =
(scala.util.control.Exception.allCatch either t).right
def readJson(dataField:Option[String],json:JsValue):Either[Throwable,JsValue] = {
for (
contents <- exp( json.asJsObject.getFields("rsp")(0) );
stat <- exp( contents.asJsObject.getFields("stat")(0).convertTo[String] );
jsonObject <- exp (
dataField match {
case Some(field) => contents.asJsObject.getFields(field)(0)
@jboner
jboner / latency.txt
Last active October 14, 2025 05:45
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@erwink
erwink / swingactors.scala
Created June 16, 2012 14:58 — forked from viktorklang/swingactors.scala
Swing Actors using Akka
// ©2012 Viktor Klang
package akka.klang
import akka.dispatch.{ DispatcherPrerequisites, ExecutorServiceFactory, ExecutorServiceConfigurator }
import com.typesafe.config.Config
import java.util.concurrent.{ ExecutorService, AbstractExecutorService, ThreadFactory, TimeUnit }
import java.util.Collections
import javax.swing.SwingUtilities