This file contains 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._ | |
def delDirNoRecur(dirName: String): Unit = { | |
val dir = new File(dirName) | |
if(dir.exists && dir.isDirectory){ | |
val files = dir.listFiles | |
files.foreach(_.delete()) | |
println(s"delete complete ${files.size} files deleted") | |
}else{ | |
println(s"$dirName not a directory") |
This file contains 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 diamondProblem | |
trait A{ | |
def hello() = println("hello from A") | |
} | |
trait B extends A{ | |
override def hello() = println("hello from B") | |
} |
This file contains 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 microbenchmarks | |
import org.scalameter.PerformanceTest | |
import org.scalameter.api._ | |
import scala.collection.mutable.ArrayBuffer | |
object CollectionAppendBenchmark extends PerformanceTest.OfflineReport { | |
val sizes: Gen[Int] = Gen.range("size")(100, 500, 100) |
This file contains 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
//this is ok | |
case class FieldName(name: String){ | |
def ::[T](v:T): T = v | |
} | |
1 :: (FieldName("yy")) | |
//doesn't work | |
case class FieldName(name: String){ |
This file contains 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
class Something{ | |
var x: Double = _ | |
var y: String = _ | |
var z: Char = _ | |
} | |
val s = new Something | |
s.x | |
s.y | |
s.z |
This file contains 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 scala.io.Source | |
def b2m(byte: Long): String = s"${byte / 1024 /1024}MB" | |
val runtime: Runtime = Runtime.getRuntime | |
println(s"max memory ${b2m(runtime.maxMemory())}MB") | |
println(s"total memory ${b2m(runtime.totalMemory())}") | |
println(s"init free memory ${b2m(runtime.freeMemory())}") | |
val file = Source.fromFile("/Users/twer/source/bigdata/data/new2.dat") | |
var size = 0 |
This file contains 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.util.Date | |
object PerfOfWhile extends App { | |
def whileLoop(size: Int): Int = { | |
var c = 0 | |
while(c < size){ | |
c += 1 | |
} | |
c | |
} |
This file contains 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 onSubmit (func: (String) ⇒ Any): (NodeSeq) ⇒ NodeSeq | |
execute the String function when the form is submitted. This method returns a function that can be applied to form fields (input, button, textarea, select) and the function is executed when the form containing the field is submitted. | |
object ChatIn { | |
| |
/** | |
* The render method in this case returns a function | |
* that transforms NodeSeq => NodeSeq. In this case, | |
* the function transforms a form input element by attaching | |
* behavior to the input. The behavior is to send a message |
This file contains 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 tryMatch: PartialFunction[Any, Unit] = { | |
case s:String => println("its a string:" + s) | |
case (s1:String,s2:String) => println("two strings:" + s1 + " and "+ s2) | |
case i:Int => println("its a int:" + i) | |
} |
This file contains 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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> | |
<title>无标题文档</title> | |
</head> | |
<body> | |
<p> </p> | |
<input id="shellcommand_in" width="800"/> |
OlderNewer