Skip to content

Instantly share code, notes, and snippets.

@ppurang
ppurang / gist:2382768
Created April 14, 2012 07:58
build.sbt for trivia
name := "coderetreat-trivia"
version := "0.0.1"
organization := "org.purang.net"
scalaVersion := "2.9.1"
libraryDependencies ++= Seq(
"org.scalaz" % "scalaz-core_2.9.1" % "6.0.3" withSources(),
@ppurang
ppurang / Global.scala
Created April 18, 2012 22:19
Play 2.0 Make Global onRouteRequest use a particular controller action if a specific header is there edit
import controllers.{routes, Application}
import play.api._
import play.api.mvc._
import play.api.mvc.Results._
import play.api.Play.current
import controllers.Utils._
object Global extends GlobalSettings {
override def onRouteRequest(request: RequestHeader): Option[Handler] = {
@ppurang
ppurang / .gitignore
Created June 5, 2012 14:20 — forked from karmi/.gitignore
Three Nodes and One Cluster: Demo of ElasticSearch's Distributed Features
.DS_Store
logs/
data/
*.html
@ppurang
ppurang / gist:3385731
Created August 18, 2012 09:51 — forked from sadache/gist:3382059
Play2 new plugin: File NonBlocking/Async API - Copying a file
"copy file" in {
val fileGenerator = Enumerator.repeat(new java.util.Date.getTime.toString + "\n").through(Enumeratee.take(1000))
//val fileGenerator = Enumerator.repeat(new java.util.Date.getTime.toString + "\n") &>> Enumeratee.take(1000)
val f = FileChannel("/tmp/testwrite.txt").delete.writing.create
val f2 = FileChannel("/tmp/testwrite2.txt").delete.writing.create
fileGenerator // generates data
.through(RichEnumeratee.binarize()) // binarizes data to write into File
@ppurang
ppurang / pr.md
Created August 20, 2012 21:24 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@ppurang
ppurang / AkkaKafkaMailboxTest.scala
Created October 4, 2012 09:54 — forked from stonegao/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
def breakIf[T: ClassTag](assertion: => Boolean, args: NamedParam*): Unit =
if (assertion) break[T](args.toList)
// start a repl, binding supplied args
def break[T: ClassTag](args: List[NamedParam]): Unit = savingContextLoader {
val msg = if (args.isEmpty) "" else " Binding " + args.size + " value%s.".format(
if (args.size == 1) "" else "s"
)
@ppurang
ppurang / isNotSameDayAndStillBefore
Created December 17, 2012 12:43
isNotSameDayAndStillBefore ..
import java.util.{Calendar => C}
import C._
def isSameDay(one: C, two: C) = one.get(ERA) == two.get(ERA) && one.get(YEAR) == two.get(YEAR) && one.get(DAY_OF_YEAR) == two.get(DAY_OF_YEAR)
//is the following the same?
def isSameDay2(one: C, two: C) = Math.abs(one.getTimeInMillis - two.getTimeInMillis) < 86400000
def isNotSameDayAndStillBefore(one: C, two: C) = !isSameDay(one, two) && one.before(two)
@ppurang
ppurang / scala meetup: May at Nokia
Last active December 17, 2015 02:59
scala meetup: May at Nokia
May is almost upon us and the series of great meetups needs to continue. This time around we are hosted by Nokia at their fairly new building. Being an ex-Nokian (hmmm did I get that right?), I am very curious how things are in the new building.
Here are the talks for the evening:
Christoph Knabe presents "Redundant History of Programming (~40 mins)
Piyush Purang presents "Spray It!" (~25 mins)
And we will start a discussion on the format of the meetups.
@ppurang
ppurang / simplesprayhttpservice.scala
Created May 15, 2013 11:08
Simple HttpService using spray with a marshaller
trait Entry extends HttpService {
val entry = path("") {
get {
complete {
Link("order", "http://localhost:8080/order", "*/*,plain/text,application/json")
}
}
}
}