Skip to content

Instantly share code, notes, and snippets.

View conikeec's full-sized avatar

Chetan Conikee conikeec

View GitHub Profile
val query = ScalasticSearch.boolQuery(
cond (
must(
'nickname -> "Superman", // is equivalent to...
term('nickname -> "Superman"), // this
term("nickname" -> "Superman") // or this
),
should(
'nickname -> "Superman", // is equivalent to...
term('nickname -> "Superman"), // this
@conikeec
conikeec / alternative, using regex
Created February 9, 2012 08:52 — forked from ArtemGr/alternative, using regex
CSV parser in Scala
val pattern = java.util.regex.Pattern.compile ("""(?xs) ("(.*?)"|) ; ("(.*?)"|) (?: \r?\n | \z ) """)
val matcher = pattern.matcher (input)
while (matcher.find) {
val col1 = matcher.group (2)
val col2 = matcher.group (4)
// ...
}
@conikeec
conikeec / gist:1807171
Created February 12, 2012 08:01 — forked from takscape/gist:1272336
Scala: Esper
import com.espertech.esper.client.{Configuration, EventBean, UpdateListener, EPServiceProviderManager}
import java.util.HashMap
import scala.collection.JavaConversions._
object Sandbox
{
def main(args: Array[String]) {
val config = new Configuration();
val eventType = new HashMap[String, AnyRef]()
eventType.put("itemName", classOf[String])
@conikeec
conikeec / EsperUtil.scala
Created February 12, 2012 08:06 — forked from wangzaixiang/EsperUtil.scala
Using Esper with Scala
package demo1
import com.espertech.esper.client.EventBean
import com.espertech.esper.client.EPAdministrator
import com.espertech.esper.client.UpdateListener
import com.espertech.esper.client.EPListenable
import com.espertech.esper.client.EPServiceProvider
object EsperUtil {
@conikeec
conikeec / mapreduce_akka.scala
Created February 14, 2012 07:12 — forked from gertjana/mapreduce_akka.scala
MapReduce example using Akka Actors
package net.addictivesoftware.scala.akkaactors
import akka.actor.{Actor, PoisonPill}
import Actor._
import akka.routing.{Routing, CyclicIterator}
import Routing._
import collection.mutable.{HashMap, Map}
import java.util.concurrent.CountDownLatch
@conikeec
conikeec / ParseLines.scala
Created February 16, 2012 19:24 — forked from seanparsons/ParseLines.scala
Useful code snippet to use when parsing large files in the Scala REPL
import scala.io.Source
def parseLines[T](file: String, transform: (Iterator[String]) => T): T = {
val log = Source.fromFile(file)
val logLines = log.getLines()
try { transform(logLines) } finally { log.close }
}
// Example usage.
// parseLines("verybigfile.txt", iterator.take(100).foreach(println))
@conikeec
conikeec / ParseLines.scala
Created February 17, 2012 00:14 — forked from seanparsons/ParseLines.scala
Useful code snippet to use when parsing large files in the Scala REPL
import scala.io.Source
def parseLines[T](file: String, transform: (Iterator[String]) => T): T = {
val log = Source.fromFile(file)
val logLines = log.getLines()
try { transform(logLines) } finally { log.close }
}
// Example usage.
// parseLines("verybigfile.txt", iterator.take(100).foreach(println))
@conikeec
conikeec / AkkaUnfilteredSample.scala
Created February 17, 2012 17:40 — forked from chrsan/AkkaUnfilteredSample.scala
Akka 2.0 unfiltered RESTful sample
package akka.unfiltered
import akka.actor._
import akka.dispatch.Future
import akka.pattern.ask
import akka.util.duration._
import akka.util.Timeout
import unfiltered.Async
import unfiltered.request._
@conikeec
conikeec / build.sbt
Created February 18, 2012 07:23 — forked from durgeshm/build.sbt
Finagle 1.9.7 with Scala 2.9.1
scalaVersion := "2.9.1"
resolvers += "durgeshm repo" at "http://durgeshm.github.com/releases/"
libraryDependencies ++= Seq(
"com.twitter" %% "finagle-core" % "1.9.7",
"com.twitter" %% "finagle-http" % "1.9.7")
@conikeec
conikeec / pipeTo.scala
Created February 19, 2012 02:20 — forked from rkuhn/pipeTo.scala
Futures and Resizers
import akka.dispatch.Future
import akka.pattern.pipe
import akka.actor.Actor
case class Work(s: String)
case class Result(s: String)
object MyActor {
// put here to avoid closing over actor’s state
def doWork(work: String): String = {