Skip to content

Instantly share code, notes, and snippets.

Working from home

Debasish Ghosh debasishg

Working from home
View GitHub Profile
View gist:370032
1. Go back to the first shell
2. Sub.unsub("a") // should unsubscribe the first shell from channel "a"
3. Study the callback function defined below. It supports many other message formats.
4. In the second shell window do the following:
scala> Pub.publish("b", "+c") // will subscribe the first window to channel "c"
scala> Pub.publish("b", "+d") // will subscribe the first window to channel "d"
scala> Pub.publish("b", "-c") // will unsubscribe the first window from channel "c"
scala> Pub.publish("b", "exit") // will unsubscribe the first window from all channels
View order.groovy'IBM')) {
limitPrice 300
allOrNone true
valueAs {qty, unitPrice -> qty * unitPrice - 500}
View order_script.groovy
def dslDef = new File('ClientOrder.groovy').text
def dsl = new File('order.dsl').text
def script = """
new GroovyShell().evaluate(script)
View gist:378251
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("groovy");
List<?> orders = (List<?>)
engine.eval(new InputStreamReader(
new BufferedInputStream(
new SequenceInputStream(
new FileInputStream("ClientOrder.groovy"),
new FileInputStream("order.dsl")))));
View gist:378252
public class RunScript {
public static void main(String[] args)
throws CompilationFailedException, IOException,
InstantiationException, IllegalAccessException {
final ClientOrder clientOrder = new ClientOrder();;
final Closure dsl =
View gist:427707
module BatchedQueue (BatchedQueue) where
import Prelude hiding (head, tail)
import Queue
data BatchedQueue a = BQ [a] [a]
check [] r = BQ (reverse r) []
check f r = BQ f r
instance Queue BatchedQueue where
View gist:491021
case class Holder(item: List[String])
implicit val HolderFormat: Format[Holder] = wrap[Holder, List[String]]("item")(_.item, Holder)
// instantiate the case class
val n = Holder(List("debasish ghosh", "jonas boner", "stephan schmidt"))
// js is a JsValue
val js = tojson(n)
// convert js to string and print
View gist:491035
// a simple POJO
case class Address(street: String, city: String, zip: String)
object AddressProtocol extends DefaultProtocol {
implicit val AddressFormat: Format[Address] =
asProduct3("street", "city", "zip")(Address)(Address.unapply(_).get)
// aggregate containing list
case class Contact(name: String, addresses: List[Address])
View gist:518613
object Protocols {
import dispatch.json._
trait HttpType
implicit val HttpTypeFormat: Format[HttpType] = new Format[HttpType] {
def reads(json: JsValue): HttpType = json match {
case JsString("Get") => Get
case JsString("Post") => Post
case _ => error("Invalid HttpType")
def writes(a: HttpType): JsValue = a match {
View gist:575091
trait Read[T] {
def read(st: String): T
implicit object IntRead extends Read[Int] {
def read(s: String) = s.toInt
implicit object StringRead extends Read[String] {
def read(s: String) = s