Skip to content

Instantly share code, notes, and snippets.

View notyy's full-sized avatar

大魔头 notyy

View GitHub Profile
@notyy
notyy / gist:2440949
Created April 22, 2012 02:16
part of timer
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)
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")
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")
@notyy
notyy / gist:2356738
Created April 11, 2012 03:55
java enum
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() {
@notyy
notyy / gist:2093930
Created March 19, 2012 03:54
monad
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)
}
}
@notyy
notyy / gist:2077987
Created March 18, 2012 17:22
andThen
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
@notyy
notyy / gist:2059567
Created March 17, 2012 14:06
call parent's method
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()
}
}
@notyy
notyy / gist:2059033
Created March 17, 2012 13:30
too easy
scala> s
res12: java.lang.String =
{
"ret":0,
"msg":"",
"nickname":"Peter",
"figureurl":"http://exmple.qq.com/qzapp/000000000000000000000000000F4262/50",
"gender":"??"
}
@notyy
notyy / gist:2055676
Created March 17, 2012 06:09
stru in haskell
withValueChecked :: Maybe a -> (a -> Maybe b) -> Maybe b
withValueChecked (Just x) f = f x
withValueChecked Nothing f = Nothing
@notyy
notyy / gist:2055464
Created March 17, 2012 05:44
so easy to define structure
// 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)