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> val source ="access_token=C4F0730***********485824&expires_in=7776000" | |
source: java.lang.String = access_token=C4F0730***********485824&expires_in=7776000 | |
scala> val (accToken, expire) = (source.split('&')(0).split('=')(1), source.split('&')(1).split('=')(1)) | |
accToken: String = C4F0730***********485824 | |
expire: String = 7776000 |
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 myFunc() = { | |
val rs = calcSomeResult() | |
logger.info("result is:" + rs) | |
rs | |
} | |
为避免上面的麻烦写法: | |
object LogUtil { | |
def kestrel[A](x: A)(f: A => Unit): A = { f(x); x } | |
def logV[A](f: String => Unit)(s: String, x: A) = kestrel(x) { y => f(s + ": " + y) } |
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 perm[T](ls: List[T]): List[List[T]] = ls match { | |
case Nil => List[Nil] | |
case xs => for{ | |
(x,i) <- ls.zipWithIndex | |
(leftX,rightX) = xs.splitAt(i) | |
ys <- perm(leftX ++ rightX.tail) | |
} yield (x:: ys) | |
} |
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
本程序逻辑如下: | |
1、列出当前目录下所有后缀名为srt的文件,过滤掉其中文件名以-3D结尾的文件 | |
2、对每个符合条件1的文件,读取其内容,通过在字幕内容中加入坐标偏移量,使之能在左右屏的3D电视上正常播放 | |
3、srt文件格式 | |
1、文件由多个段落组成,段落之间以空行分隔 | |
2、每段落中的内容由3部分组成 | |
1、序号 | |
2、时间量 | |
3、字幕内容 | |
4、转换逻辑是将原字幕内容分别在前面加上偏移量{\pos(96,255)\fscx50}和{\pos(288,255)\fscx50},变成两段内容,一个序号保持不变,位置也不变,而另一段必须加到原内容最后,序号递增 |
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 showType: Any => String = { | |
case s:String => "it's a String:" + s | |
case i:Int => "it's a Int:" + i | |
case l:List[Any] => "it's a List,length: " + l.length | |
case _ => "I don't know" | |
} | |
def showTypeM(t:Any):String = t match { | |
case s:String => "it's a String:" + s | |
case i:Int => "it's a Int:" + i |
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 m2(x:Int) = x * 2 | |
def p1(x:Int) = x + 1 | |
scala> (1 to 5).map(m2).map(p1) | |
res3: scala.collection.immutable.IndexedSeq[Int] = Vector(3, 5, 7, 9, 11) | |
scala> (1 to 5).map(m2 _ andThen p1) | |
res9: scala.collection.immutable.IndexedSeq[Int] = Vector(3, 5, 7, 9, 11) |
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 Fruit { | |
def selfIntro() = "Fruit" | |
} | |
class Apple extends Fruit{ | |
override def selfIntro() = "Apple" | |
} | |
class Package[T] (val contents:Seq[T]) { | |
def this() = this(List[T]()) |
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 s = "abc"; | |
List<Object> objects = new java.util.ArrayList<String>(); | |
String[] a = new String[] { "abc" }; | |
Object[] b = a; | |
b[0] = 1; | |
System.out.println(a[0]); |
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 Father { | |
def say() { | |
Console.println("I am father") | |
} | |
} | |
class Son extends Father { | |
override def say() { | |
Console.println("I am son") | |
} |
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 Main extends App { | |
object SearchCodeEnum extends Enumeration { | |
type SearchCodeValue = Value | |
val org = Value | |
val file = Value | |
} | |
for(code <- SearchCodeEnum.values) {println(code)} | |
} |