This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mycompany | |
import org.scalatra._ | |
class Uploader extends ScalatraFilter { | |
get("/test"){ | |
status ( 202 ) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mycompany | |
import org.scalatest.FunSuite | |
import org.scalatest.matchers.ShouldMatchers | |
import org.scalatra.test.ScalatraTests | |
class UploaderTest extends FunSuite with ShouldMatchers with ScalatraTests{ | |
routeFilter(classOf[Uploader], "/*") | |
test("simple get") { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> | |
<!-- =============================================================== --> | |
<!-- Configure the Jetty Server --> | |
<!-- --> | |
<!-- Documentation of this file format can be found at: --> | |
<!-- http://docs.codehaus.org/display/JETTY/jetty.xml --> | |
<!-- --> | |
<!-- =============================================================== --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def castToInt(any: Option[Any]): Option[Int] = { | |
any match { | |
case Some(value: Int) => Some(value) | |
case _ => None | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@tailrec | |
def splitHelper[T](l : List[T], b: ListBuffer[List[T]])(c: T => Boolean) : List[List[T]] = { | |
l match { | |
case Nil => b.result() | |
case h :: t => | |
val (h, t) = l.tail.span(c) | |
b += l.head :: h ::: Nil | |
splitHelper(t, b)(c) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.ByteArrayInputStream | |
import java.util.zip.GZIPOutputStream | |
import java.util.zip.GZIPInputStream | |
import java.io.ByteArrayOutputStream | |
val buffer = new Array[Byte](1024*4) | |
def gzip(bytes: Array[Byte]) = { | |
val byteIn = new ByteArrayInputStream(bytes) | |
val byteOut = new ByteArrayOutputStream() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def benchmark(runs: Long, reps: Long, funct: => Any) = { | |
// warmup | |
println("Warming Up") | |
var i = 0 | |
while ( i < 25000 ) { funct; i = i + 1 } | |
// test runs | |
println("Running Test") | |
var j = 0 | |
while ( j < runs ) { | |
var k = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> val builder = Set.newBuilder[Array[Byte]] | |
builder: scala.collection.mutable.Builder[Array[Byte],scala.collection.immutable.Set[Array[Byte]]] = scala.collection.mutable.AddingBuilder@22509bfc | |
scala> for(_ <- 0 until 10) builder += Array[Byte](1,2,3) | |
scala> builder.result() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Needed to gain control over which jackson version we use | |
override def ivyXML = | |
<dependencies> | |
<dependency org="com.amazonaws" name="aws-java-sdk" rev="1.2.8"> | |
<exclude module="jackson-core-asl"/> | |
</dependency> | |
</dependencies> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaj.collection.Imports._ | |
import org.yaml.snakeyaml.Yaml | |
def parse(str: String) = { | |
new Yaml().load(str) match { | |
case obj: ArrayList[_] => | |
val seqOfMaps = obj.asScala.collect { | |
case hashMap: HashMap[_, _] => | |
hashMap.asScala.toMap.asInstanceOf[Map[String, Any]] | |
}.toSeq |
OlderNewer