Skip to content

Instantly share code, notes, and snippets.

@itang
itang / sbt.sublime-build
Created July 6, 2011 08:53
sbt build script for sublime text editor [windows]
{
"cmd": ["xsbt compile"],
"file_regex": "^\\[error\\] ([.a-zA-Z0-9/-]+[.]scala):([0-9]+):",
"selector": "source.scala",
"working_dir": "${project_path:${folder}}",
"shell": "true",
"encoding": "GBK"
}
Runtime.getRuntime.addShutdownHook(new Thread{ override def run = println("exit!!!") })
scala> def a[T](i:T)(implicit ev: =:=[String, T]) = println(i)
a: [T](i: T)(implicit ev: =:=[String,T])Unit
scala> def test[T <: Any](a : T)(implicit ev : T =:= String) = println(a)
test: [T](a: T)(implicit ev: =:=[T,String])Unit
scala> test("aa")
aa
scala> test(1)
scala> def a(x: Int) = {println("evaluated"); x * 100 }
a: (x: Int)Int
scala> val s : Stream[Int] = 1 #:: 2 #:: 3 #:: a(100) #:: Stream.empty
s: Stream[Int] = Stream(1, ?)
scala> s(0)
res0: Int = 1
@itang
itang / case_func.scala
Created July 15, 2011 07:56
Pattern Matching Anonymous Functions
List(("a",1),("b",2)).map(case (x,y) => x + y)
List(("a",1),("b",2)).map{case (x,y) => x + y}
val func0: (Int, Int)=>Int = case (x, y)
val func1: (Int, Int)=>Int = { case (x, y) => x + y }
func1(1, 2)
func1(1->2)
object ParBenchmark {
case class Result(item: Int, c: Long, p: Long) {
override def toString = "%-10s\t%-10d\t%-10d".format(item, c, p)
}
def time(proc: => Any) = {
def curr = System.currentTimeMillis
val s = curr; proc; curr - s
}
def even(i: Int) = i % 2 == 0
@itang
itang / BlueEyesDemo.scala
Created July 23, 2011 18:11
simple benchmark for Blueeyes, Servlet, Play!
package demo
import blueeyes.BlueEyesServer
import blueeyes.BlueEyesServiceBuilder
import blueeyes.concurrent.Future
import blueeyes.concurrent.Future._
import blueeyes.core.data.{ ByteChunk, BijectionsChunkJson }
import blueeyes.core.http.HttpStatusCodes._
import blueeyes.core.http.combinators.HttpRequestCombinators
import blueeyes.core.http.MimeTypes._
@itang
itang / clojure.sh
Created July 30, 2011 14:43
Clojure launcher for linux
#!/bin/bash --posix
## modified from Scala shell
#
##############################################################################
# Copyright 2002-2011, LAMP/EPFL
#
# This is free software; see the distribution for copying conditions.
# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
##############################################################################
package test;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.concurrent.Callable;
import api.Unchecked;
public class Test {
package test
import com.codahale.jerkson.Json._
import scala.reflect.BeanInfo
import scala.reflect.BeanProperty
object TestJerkson extends App {
def p(t: Any) = println(generate(t))
implicit def pw(t: Any) = new {
def output_json = p(t)
}