Skip to content

Instantly share code, notes, and snippets.

View oluies's full-sized avatar

Örjan Angré (Lundberg) oluies

  • Sweden
  • 11:37 (UTC +02:00)
  • X @oluies
View GitHub Profile
@guillaumebort
guillaumebort / Procfile
Created June 22, 2012 16:04
Configuration for a blocking Play 2.0 application
web: target/start -Dhttp.port=${PORT} -Dconfig.resource=prod.conf ${JAVA_OPTS}
@jboner
jboner / latency.txt
Last active May 13, 2025 17:54
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
@guillaumebort
guillaumebort / 1.sql
Created May 25, 2012 15:17
Play 2.0/Anorm
# --- !Ups
CREATE TABLE users(
email VARCHAR(255) NOT NULL PRIMARY KEY,
name VARCHAR(255)
);
CREATE TABLE subjects(
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
title LONGTEXT NOT NULL,
@sadache
sadache / funky.scala
Created May 16, 2012 19:47 — forked from jto/funky.scala
Funky enumerator usage
package controllers
import play.api._
import play.api.mvc._
import play.api.libs.ws._
import play.api.libs.iteratee._
import play.api.libs.concurrent._
object Application extends Controller {
@stonegao
stonegao / AkkaKafkaMailboxTest.scala
Created May 1, 2012 07:24 — forked from mardambey/AkkaKafkaMailboxTest.scala
Akka 2.0 actors with Kafka backed durable mailboxes.
import akka.actor.Actor
import akka.actor.ActorSystem
import akka.agent.Agent
import com.typesafe.config.ConfigFactory
import akka.event.Logging
import akka.actor.Props
import kafka.utils.Utils
import java.nio.ByteBuffer
@fcroiseaux
fcroiseaux / ServerEventsComparison.scala
Created April 28, 2012 11:28
Comparison of Comet, SSE and WebSocket server to client communication with Playframework 2.0 in Scala
/**
* Handles the comet event stream.
*/
def cometStream = Action {
AsyncResult {
implicit val timeout = Timeout(5.seconds)
val actor=Akka.system.actorOf(Props[EventListener])
// Actor is listening for event on the eventStream
Akka.system.eventStream.subscribe(actor,classOf[ChangeEvent])
// For each event, stream the data to client
@retronym
retronym / unimplicitly.scala
Created April 20, 2012 20:59
unimplicitly
scala> import scala.language.experimental.macros
import scala.language.experimental.macros
scala> def unimplicitlyImpl[A: c.TypeTag](c: reflect.makro.Context) = {
| val A = implicitly[c.TypeTag[A]].tpe
| val i = c.inferImplicitValue(A, silent = true)
| if (i == c.mirror.EmptyTree) c.reify(())
| else sys.error("unexpected implicit of type %s: %s".format(A, i))
| }
unimplicitlyImpl: [A](c: scala.reflect.makro.Context)(implicit evidence$1: c.TypeTag[A])c.mirror.Expr[Unit]
@ThomasAlexandre
ThomasAlexandre / JFokus 2012 scala oneliners.scala
Created February 15, 2012 20:16
JFOKUS 2012 Sample from "One-liners are your friend"
case class Deal( title:String = "", discount:Int = 0, city:String = "" )
val deal = Deal()
val deal = Deal("Hotel")
val deal = Deal("Hotel",city="Paris")
val betterDeal = deal.copy(discount=50)
import dispatch._
val request = url("http://localhost:8086/deals")
Http( request >>> System.out)
val deals = Http( request as_str )
val dealsAsXml = Http( request.handleResponseAsXml({ response => response }) )
@stonegao
stonegao / rest.scala
Created October 9, 2011 16:05 — forked from robi42/rest.scala
Basic RESTful service with Finagle
class Respond extends Service[Request, Response] with Logger {
def apply(request: Request) = {
try {
request.method -> Path(request.path) match {
case GET -> Root / "todos" => Future.value {
val data = Todos.allAsJson
debug("data: %s" format data)
Responses.json(data, acceptsGzip(request))
}
case GET -> Root / "todos" / id => Future.value {
@kevinwright
kevinwright / PimpMyFilter.scala
Created October 4, 2011 22:11
Pimpin' + on a T => Either[ERR,T] for easy chaining
class Filters[T] {
//Some boilerplate-busting aliases
type FilterResult = Either[Rejection, T]
type FilterFunc = (T) => FilterResult
//Handy helpers
//Rejection can carry as much info as you wish;
// Filter name, value in error, an exception, etc.
case class Rejection(input: T, msg: String)