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 org.scalaconsole | |
import swing.TextComponent | |
import javax.swing.JTextPane | |
import util.regexp.PointedHedgeExp | |
import java.awt.{Graphics2D, Point} | |
class TextPane extends TextComponent { | |
override lazy val peer: JTextPane = new JTextPane() with SuperMixin |
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
#!/bin/sh | |
exec scala $0 $@ | |
!# | |
import java.io._ | |
def cwd = System.getProperty("user.dir") | |
def setCwd(s:String) { | |
if(!new File(s).exists()) |
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 quicksort[T : Ordering](l: List[T]) : List[T] = l match { | |
case Nil => Nil | |
case x :: xs => | |
val ord = Ordering[T] | |
import ord._ | |
val smaller = quicksort(xs.filter(_<=x)) | |
val bigger = quicksort(xs.filter(_>x)) | |
smaller ++ List(x) ++ bigger | |
} |
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
#!/bin/sh | |
exec scala $0 $0 $@ | |
!# | |
/** | |
* This script finds the newest sbt-launch.jar from its official repository, | |
* update the one in th same directory of this script if necessary. | |
* it manages the current sbt version in a companion file 'current_sbt_version' | |
* and will create it if not already exists. | |
*/ |
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
::#! | |
@echo off | |
call scala .\%0 .\%0 %* | |
goto :eof | |
::!# | |
/** | |
* This script finds the newest sbt-launch.jar from its official repository, | |
* update the one in th same directory of this script if necessary. | |
* it manages the current sbt version in a companion file 'current_sbt_version' |
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 collection.mutable.ListBuffer | |
case class Part(contentType:Option[String], encoding:Option[String], location:Option[String], data:ListBuffer[String]) | |
var boundary: String = null | |
val Boundary = """.*boundary="(.*)"""".r | |
var state = 0 | |
val IN_PART = 1 | |
val IN_DATA = 2 |
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
case class Message(username:String, content:String) | |
val list = List(Message("aaa", "111"), Message("aaa","222"), | |
Message("bbb","333"),Message("aaa", "444")) | |
import collection.mutable.ListBuffer | |
list.foldLeft(new ListBuffer[(String,ListBuffer[Message])]()){ | |
case (buff, item) => | |
if(buff.nonEmpty && buff.last._1 == item.username) buff.last._2 += item |
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 xml._ | |
case class CssSelector(css:String) { | |
def find(node:Node):Seq[Node] | |
def unique(node:Node):Option[Node] = find(node).headOption | |
} | |
assert(CssSelector("div.some_class").unique(<div><div class="some_class">abc</div></div>).get.text == "abc") | |
assert(CssSelector("div#some_id span.some_class".unique( | |
<div id="some_id" class="any_class"> |
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 ShhConsumeTest extends Logging with FunSuite{ | |
val pos = new ShhVirtualPos("192.168.1.14", 5960, "206290010320001", "20000005") | |
var card = Card("9444443228739457375", "954000") | |
test("send") { | |
assert(pos.签到.result === OK) | |
val 消费交易 = card 在 pos 消费 Money(9.63) | |
assert(消费交易.result === OK) | |
} | |
} |
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 doSomethingIfNoNull(name:String, password:String, other:String, doSomething: =>String): Option[String] = { | |
for(n <- Option(name); | |
p <- Option(password); | |
o <- Option(other)) | |
yield(doSomething) | |
} | |
assert(doSomethingIfNoNull("abc", null, "cde", "Do something") == None) | |
assert(doSomethingIfNoNull(null, "abc", "cde", "Do something") == None) | |
assert(doSomethingIfNoNull("abc", "cde", null, "Do something") == None) |
OlderNewer