Skip to content

Instantly share code, notes, and snippets.

View notyy's full-sized avatar

大魔头 notyy

View GitHub Profile
@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?
@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 }
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 / whileLoop.scala
Last active August 29, 2015 14:13
trying to figure out why foreach is slow
import java.util.Date
object PerfOfWhile extends App {
def whileLoop(size: Int): Int = {
var c = 0
while(c < size){
c += 1
}
c
}
@notyy
notyy / StreamBench.scala
Last active August 29, 2015 14:11
stream memory
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
class Something{
var x: Double = _
var y: String = _
var z: Char = _
}
val s = new Something
s.x
s.y
s.z
//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){
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)