Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / TCBedCon2012.scala
Created March 30, 2012 13:27
bedcon 2012 presentation script
:silent
//the following are helper functions
def p = if(readLine() == "q") sys.exit
def pp[A]: ( => A) => Unit = a => {readLine() ; a}
object > {
def > : String => Unit = println _
def >[A] : (String, => A) => Unit = (a,b) => {print("> " + a); readLine(); readLine(); println(" ----> " + b); println}
}
@ppurang
ppurang / gist:1895676
Created February 23, 2012 23:24
extreme stratup
val add = """.*: what is (\d*) plus (\d*)""".r
q match {
case add(a, b) =>(a.toInt + b.toInt).toString
case bond() => // well we don't want to reveal too much
case banana() => //but bond and banana ought to get the attention.
case _ => ""
}
@ppurang
ppurang / directions.hs
Created December 4, 2011 11:27
map a list of functions to a single value
-- import Control.Monad (ap)
type Pos = (Int, Int)
type Direction = Pos -> Pos
direction :: Pos -> [Direction] -> [Pos]
direction p [] = []
direction p (x:xs) = x p : direction p xs
-- another way
-- direction p ds = ap ds [p]
@ppurang
ppurang / shebang
Created November 22, 2011 22:12
scala script including a proper classpath
#!/bin/sh
L=`dirname $0`/../lib
cp=`echo $L/*.jar|sed 's/ /:/g'`
exec scala -classpath $cp -savecompiled $0 $@
!#
# shebang magic from http://www.eamonn.org/blog/archives/425
println("hello world")
@ppurang
ppurang / SlogBuild.scala
Created August 22, 2011 17:19
scala sbt 10 multi module project
import sbt._
import Keys._
import sbt.Package._
import java.util.jar.Attributes.Name._
import com.github.siasia.WebPlugin._
//unashamed copy of scalaz's build
object SlogBuild extends Build {
override lazy val settings = super.settings :+
//performance is not everything
//can this be parallel?
def isPalindrome(list: List[Int]) = {
(list zip list.reverse filter (a => a._1 != a._2) size) == 0
}