Skip to content

Instantly share code, notes, and snippets.

View notyy's full-sized avatar

大魔头 notyy

View GitHub Profile
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")
package diamondProblem
trait A{
def hello() = println("hello from A")
}
trait B extends A{
override def hello() = println("hello from B")
}
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 is ok
case class FieldName(name: String){
def ::[T](v:T): T = v
}
1 :: (FieldName("yy"))
//doesn't work
case class FieldName(name: String){
class Something{
var x: Double = _
var y: String = _
var z: Char = _
}
val s = new Something
s.x
s.y
s.z
@notyy
notyy / StreamBench.scala
Last active August 29, 2015 14:11
stream memory
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
@notyy
notyy / whileLoop.scala
Last active August 29, 2015 14:13
trying to figure out why foreach is slow
import java.util.Date
object PerfOfWhile extends App {
def whileLoop(size: Int): Int = {
var c = 0
while(c < size){
c += 1
}
c
}
@notyy
notyy / gist:1235065
Created September 22, 2011 15:28
onsubmit def
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
@notyy
notyy / gist:1234930
Created September 22, 2011 14:35
can match any parameter
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)
}
@notyy
notyy / gist:1241798
Created September 26, 2011 07:42
width no use?
<!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>&nbsp;</p>
<input id="shellcommand_in" width="800"/>