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 getPrime(n:Long,x:Long): (Long,Long) = if(n % x == 0) (x, n / x) else getPrime(n,x+1) | |
def problem3(n:Long):Long = { | |
getPrime(n,2) match { | |
case (x,_) if(x == n) => n | |
case (_,y) => problem3(y) | |
} | |
} |
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
本程序逻辑如下: | |
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 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 Html exposing (..) | |
import Html.App as Html | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (onInput, onClick) | |
import String exposing (length) | |
main = | |
Html.beginnerProgram | |
{ model = { name = "", password = "", passwordAgain = "", validationResult = NotDone } |
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 concurrency.future | |
import com.typesafe.scalalogging.StrictLogging | |
import scala.concurrent.{Await, Future} | |
import scala.concurrent.duration._ | |
import scala.language.postfixOps | |
import scala.concurrent.ExecutionContext.Implicits.global | |
object FutureAwait extends App with StrictLogging { |
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 org.springframework.context.support.ClassPathXmlApplicationContext; | |
import com.alibaba.dubbo.demo.UserService; | |
public class Consumer { | |
public static void main(String[] args) throws Exception { | |
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"http://10.20.160.198/wiki/display/dubbo/consumer.xml"}); | |
context.start(); | |
UserService userService = (UserService)context.getBean("userService"); // get remote proxy |
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
trait ReactiveComponent[Input, Output] | |
trait SimpleTransformation[Input, Output] extends ReactiveComponent[Input, Output] { | |
val outer = this | |
def update(input: Input): Output | |
def conn[Output1](nextSimpleTrans: SimpleTransformation[Output, Output1]): SimpleTransformation[Input, Output1] = { | |
new SimpleTransformation[Input, Output1] { | |
override def update(input: Input): Output1 = { | |
val output: Output = outer.update(input) //outer.update return's Output1 type? |
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 scala.math._ | |
case class Point(x:Int, y:Int) | |
def isSquare(p1: Point, p2: Point, p3: Point, p4: Point): Boolean = { | |
val points = Set(p2,p3,p4) | |
(for{ | |
p1_x_Neighbor <- points.find(_.x == p1.x) | |
p1_y_Neighbor <- points.find(_.y == p1.y) | |
if abs(p1_y_Neighbor.x - p1.x) == abs(p1_x_Neighbor.y - p1.y) |
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 scala.concurrent.{ future, promise } | |
import scala.concurrent.ExecutionContext.Implicits.global | |
val p = promise[String] | |
val f = p.future | |
val producer = future { | |
println("producing") | |
Thread.sleep(1000) | |
val r = "produced" | |
p success r | |
Thread.sleep(1000) |
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
//database model | |
case class Account(id: Identifier, owner: User, var balance: Money) | |
object AccountRepository { | |
def lookUp(id: Int):Account = Account("id1", "notyy", 100.0) //just an example | |
} | |
//DCI model | |
class AccountHolder(val account: Account) //adaptor |
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 notyy; | |
public class Option<A> { | |
private final A thing; | |
public Option(A thing) { | |
this.thing = thing; | |
} | |
public <E extends Exception> A getOrThrow(E excetion) throws E{ |
NewerOlder