Skip to content

Instantly share code, notes, and snippets.

View notyy's full-sized avatar

大魔头 notyy

View GitHub Profile
@notyy
notyy / gist:1347823
Created November 8, 2011 14:13
cool
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)
}
}
@notyy
notyy / gist:1869326
Created February 20, 2012 13:55
2D字幕文件转3D
本程序逻辑如下:
1、列出当前目录下所有后缀名为srt的文件,过滤掉其中文件名以-3D结尾的文件
2、对每个符合条件1的文件,读取其内容,通过在字幕内容中加入坐标偏移量,使之能在左右屏的3D电视上正常播放
3、srt文件格式
1、文件由多个段落组成,段落之间以空行分隔
2、每段落中的内容由3部分组成
1、序号
2、时间量
3、字幕内容
4、转换逻辑是将原字幕内容分别在前面加上偏移量{\pos(96,255)\fscx50}和{\pos(288,255)\fscx50},变成两段内容,一个序号保持不变,位置也不变,而另一段必须加到原内容最后,序号递增
@notyy
notyy / 3-form.elm
Last active July 21, 2019 17:46
implement a submit button in elm form guide
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 }
@notyy
notyy / Future.scala
Created February 1, 2018 03:50
future in different thread
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 {
@notyy
notyy / dubbosample.java
Last active November 2, 2016 13:05
a dubbo sample
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
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?
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)
@notyy
notyy / future.scala
Created November 25, 2013 12:32
first code block use future promise second only use future
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)
@notyy
notyy / dci.scala
Last active December 27, 2015 07:29
//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
@notyy
notyy / code.java
Last active December 22, 2015 05:19
Option in java
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{