Skip to content

Instantly share code, notes, and snippets.

View debasishg's full-sized avatar
🏠
Working from home

Debasish Ghosh debasishg

🏠
Working from home
View GitHub Profile
Welcome to Scala version 2.9.0.final (OpenJDK Server VM, Java 1.6.0_20).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import tools.scalap.scalax.rules.scalasig._
import tools.scalap.scalax.rules.scalasig._
scala> import scala.runtime._
import scala.runtime._
@debasishg
debasishg / gist:982435
Created May 20, 2011 06:19
decorators with registration
describe("decorators") {
trait Window {
var ds = Map.empty[String, Decorator]
def register(d: Decorator) = ds += ((d.id, d))
def deregister(d: Decorator) = ds -= d.id
}
case class MWindow(x: Int, y: Int) extends Window {
}
@debasishg
debasishg / gist:1032448
Created June 17, 2011 21:56
getting this error from dispatch-http 0.8.1
java.lang.IllegalStateException: Invalid use of SingleClientConnManager: connection still allocated.
Make sure to release the connection before allocating another one.
at org.apache.http.impl.conn.SingleClientConnManager.getConnection(SingleClientConnManager.java:218)
at org.apache.http.impl.conn.SingleClientConnManager$1.getConnection(SingleClientConnManager.java:192)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:391)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:776)
at dispatch.BlockingHttp$class.dispatch$BlockingHttp$$execute(Http.scala:45)
at dispatch.BlockingHttp$$anonfun$execute$1$$anonfun$apply$3.apply(Http.scala:58)
at dispatch.BlockingHttp$$anonfun$execute$1$$anonfun$apply$3.apply(Http.scala:58)
@debasishg
debasishg / gist:1033135
Created June 18, 2011 14:26
error running view queries
## couchdb.stdout
[error] [<0.1313.0>] OS Process Error <0.279.1> :: {os_process_error, {exit_status,1}}
[error] [<0.1313.0>] OS Process Error <0.282.1> :: {os_process_error,
{exit_status,1}}
<<lots of same message>>
## couchdb.stderr
@debasishg
debasishg / gist:1033468
Created June 18, 2011 20:13
Error in interpreter ..
Welcome to Scala version 2.9.0.final (Java HotSpot(TM) Server VM, Java 1.6.0_24).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.tools.nsc.interpreter.IMain
import scala.tools.nsc.interpreter.IMain
scala> val i = new IMain
i: scala.tools.nsc.interpreter.IMain = scala.tools.nsc.interpreter.IMain@d5b561
@debasishg
debasishg / gist:1059864
Created July 2, 2011 08:37
Tony Morris' Option using catamorphism
trait MyOption[+A] {
// single abstract method
def cata[X](some: A => X, none: => X): X
import MyOption._
def map[B](f: A => B): MyOption[B] = cata(f andThen some, none)
// Also
// def map[B](f: A => B): MyOption[B] = flatMap(f andThen some)
@debasishg
debasishg / gist:1059896
Created July 2, 2011 09:32
Tony Morris - catamorphism with cons list
// Church-encoded cons list
trait MyList[A] {
def foldRight[B]: (A => B => B) => B => B
}
object MyList {
def nil[A]: MyList[A] = new MyList[A] {
def foldRight[B] =
_ => z => z
}
@debasishg
debasishg / gist:1080967
Created July 13, 2011 18:35
samples of monad transformers in scalaz
scala> List(10, 12).transLift[OptionT].runT
res12: List[Option[Int]] = List(Some(10), Some(12))
scala> optionT(List(some(12), some(50))).runT
res13: List[Option[Int]] = List(Some(12), Some(50))
scala> List(some(12), some(50))
res14: List[Option[Int]] = List(Some(12), Some(50))
scala> optionT(List(some(12), some(50)))
scala> val l = List(10, 100, 1000, 10000)
l: List[Int] = List(10, 100, 1000, 10000)
scala> l.orElse[Int, Int]{ case i: Int => 34 }
res14: PartialFunction[Int,Int] = <function1>
scala> res14(0)
res15: Int = 10
scala> res14(10)
@debasishg
debasishg / gist:1136502
Created August 10, 2011 10:14
Problem loading a Scala *object* reflectively ..
Foo.scala as ..
package net.debasishg.domain.trade.service
trait Foo {
final val foo: Int => Int = {i => i * 2}
}
object Foo extends Foo
and a test spec TSpec.scala as ..