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
module Main where | |
import Graphics.UI.WX | |
import Graphics.UI.WXCore.WxcClassesAL(getApplicationDir,getApplicationPath) | |
import Data.Time(getZonedTime,formatTime) | |
import System.Locale(defaultTimeLocale) | |
import System.FilePath((</>)) | |
import Data.Char | |
import TimeCalc(timeUp,reduceTime) |
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
object Succ { | |
def main(args: Array[String]) { | |
assert(succ("") == "") | |
assert(succ("3") == "4") | |
assert(succ("R2D3") == "R2D4") | |
assert(succ("R293") == "R294") | |
assert(succ("R2D9") == "R2E0") | |
assert(succ("A99") == "B00") | |
assert(succ("Z99") == "AA00") | |
assert(succ("Zz99") == "AAa00") |
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
object Succ { | |
def main(args: Array[String]) { | |
assert(succ("") == "") | |
assert(succ("3") == "4") | |
assert(succ("R2D3") == "R2D4") | |
assert(succ("R293") == "R294") | |
assert(succ("R2D9") == "R2E0") | |
assert(succ("A99") == "B00") | |
assert(succ("Z99") == "AA00") | |
assert(succ("Zz99") == "AAa00") |
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
public enum Orientation { | |
East("E"), South("S"), West("W"), North("N"); | |
private final String id; | |
private Orientation(String id) { | |
this.id = id; | |
} | |
public String getId() { |
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
class Monadic[A, B](val f1: (A => Option[B])) { | |
def then[C]: (B => Option[C]) => (A => Option[C]) = thenDo(f1) _ | |
def thenDo[A, B, C](fa2ob: (A => Option[B]))(fb2oc: (B => Option[C])): (A => Option[C]) = { a => | |
fa2ob(a) match { | |
case None => None | |
case Some(b) => fb2oc(b) | |
} | |
} |
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 step1 : Int => Int = _ + 2 | |
def step2: Int => String = _.toString | |
def step3: String => Unit = (s) => println(s + " good") | |
val all = step1 andThen step2 andThen step3 | |
---------------------------------------- | |
scala> :l AndThen.scala | |
Loading AndThen.scala... | |
step1: Int => Int | |
step2: Int => String |
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
class Daddy { | |
def sayMe() = println("I am your daddy" ) | |
} | |
class Son extends Daddy { | |
override def sayMe() = { | |
println("I am son,for now,but when I grow up ,I will say:") | |
super.sayMe() | |
} | |
} |
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
scala> s | |
res12: java.lang.String = | |
{ | |
"ret":0, | |
"msg":"", | |
"nickname":"Peter", | |
"figureurl":"http://exmple.qq.com/qzapp/000000000000000000000000000F4262/50", | |
"gender":"??" | |
} |
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
withValueChecked :: Maybe a -> (a -> Maybe b) -> Maybe b | |
withValueChecked (Just x) f = f x | |
withValueChecked Nothing f = Nothing |
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
// original version | |
def extractToken(resp: Option[String]): Option[Token] = { | |
logger.info("extracting token from:" + resp) | |
val AccRegex = """(.*)=(.*)&(.*)=(\d*)""".r | |
val ErrRegex = """(.*)"error":(.*),"error_description":"(.*)"}(.*)""".r | |
resp match { | |
case None => logV(logger.error)("can't extract from empty token resp", None) | |
case Some(source) => source match { | |
case AccRegex(_, accToken, _, expire) => logV(logger.info)("token extracted:", Some(Token(accToken, expire.toLong))) | |
case ErrRegex(_, errCode, errMsg, _) => logV(logger.info)("server respond with error:code=" + errCode + ",msg=" + errMsg, None) |