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 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
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 java.util.Date | |
object PerfOfWhile extends App { | |
def whileLoop(size: Int): Int = { | |
var c = 0 | |
while(c < size){ | |
c += 1 | |
} | |
c | |
} |
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.io.Source | |
def b2m(byte: Long): String = s"${byte / 1024 /1024}MB" | |
val runtime: Runtime = Runtime.getRuntime | |
println(s"max memory ${b2m(runtime.maxMemory())}MB") | |
println(s"total memory ${b2m(runtime.totalMemory())}") | |
println(s"init free memory ${b2m(runtime.freeMemory())}") | |
val file = Source.fromFile("/Users/twer/source/bigdata/data/new2.dat") | |
var size = 0 |
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
class Something{ | |
var x: Double = _ | |
var y: String = _ | |
var z: Char = _ | |
} | |
val s = new Something | |
s.x | |
s.y | |
s.z |
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
//this is ok | |
case class FieldName(name: String){ | |
def ::[T](v:T): T = v | |
} | |
1 :: (FieldName("yy")) | |
//doesn't work | |
case class FieldName(name: String){ |
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 microbenchmarks | |
import org.scalameter.PerformanceTest | |
import org.scalameter.api._ | |
import scala.collection.mutable.ArrayBuffer | |
object CollectionAppendBenchmark extends PerformanceTest.OfflineReport { | |
val sizes: Gen[Int] = Gen.range("size")(100, 500, 100) |
NewerOlder