전체 글
-
impure run 사용하기web/mhtml 2021. 10. 28. 00:15
코드 import mhtml._ import org.scalajs.dom import scala.scalajs.js object MHtmlTest { def view(): Unit = { val x: Var[List[String]] = Var(List("a", "b", "c")) val first: Var[String] = Var("Z") // x.map(list => first := list.head).impure.run(_ => ()) x.impure.run(list => first := list.head) val content = {first} x.update(list => e.target.value.asInstanceOf[String] :: list) } /> mount(dom.document.g..
-
mhtml Rx 이해하기 - Ajax 호출시 경험web/mhtml 2021. 10. 27. 23:28
문제 다음 코드는 유효한 url 을 호출하였음에도 브라우저 콘솔에서 에러 메시지를 볼 수 있다. import mhtml._ import mhtml.future.syntax.FutureToRxSyntax import org.scalajs.dom import org.scalajs.dom.ext.Ajax import scala.concurrent.ExecutionContext.Implicits.global import scala.util.Success object MHtmlTest { def view(): Unit = { val url: String = "https://jsonplaceholder.typicode.com/todos/1" val response: Rx[List[String]] = Ajax.get..
-
mhtml 에서 imitate 로 Var 값에 Rx 복사하기web/mhtml 2021. 10. 25. 22:07
문제 mhtml 에서 아래와 같이 x, y 가 있을 때 x 값에 y 를 복사해 보자 val x: Var[Int] = Var(1) val y: Var[Int] = Var(2) 코드 mhtml 의 imitate 를 사용해 복사할 수 있다. import mhtml._ import org.scalajs.dom object MHtmlTest { def view(): Unit = { val x: Var[Int] = Var(1) val y: Var[Int] = Var(2) val z: Rx[Int] = x.imitate(y) val content = {x} {z} mount(dom.document.getElementById("main_content"), content) } } 화면에 x, z 값이 노출되어 2 2 를..
-
javascript callback 처리 하기 - checkboxweb/mhtml 2021. 10. 25. 15:09
문제 dropdown callback 처리 처럼 reactive, non-reactive 하게 각각 사용할 수 있다. 여기서는 reactive 하게 동작하게 해 보자. 코드 import mhtml._ import org.scalajs.dom import scala.scalajs.js val isChecked: Var[Boolean] = Var(false) val content = isChecked := e.target.checked.asInstanceOf[Boolean]}> Label isChecked: {isChecked.map(_.toString)} mount(dom.document.getElementById("main_content"), content) import mhtml._ import org..
-
javascript callback 처리 하기 - dropdownweb/mhtml 2021. 10. 25. 14:01
문제 scalajs 에서 fomantic-ui dropdown module 을 사용하기 위해서는 javascript callback 을 등록해 줘야 한다. dropdown 동작 방식 처리는 아래와 같이 2가지로 할 수 있다. dropdown 메뉴에서 아이템이 선택되면 바로 UI 갱신 (reactive) 아이템을 선택한 후 별도의 버튼을 누르면 그 때 선택된 아이템을 읽어 UI 갱신 (non-reactive) fomantic-ui example 을 대상으로 mhtml 을 함께 사용해 구현해 보자 코드 reactive 방식 import mhtml._ import org.scalajs.dom import scala.scalajs.js val selectedGender: Var[String] = Var("") ..
-
Rest API 로 특정 색인의 특정 항목만 보기elasticsearch 2021. 10. 24. 23:37
문제 elasticsearch rest api 로 색인을 조회하기 위해 아래와 요청 하면 /_cat/indices 결과는 아래처럼 나온다. green open rising-batch-20211024 ea1Pke2LQ1-hqy822TbOCw 20 1 2264383 0 1.1gb 603.5mb green open rising-stream-20211021 xZLXfZzMQC-4RT2Td1T66A 20 1 5243762 0 2.5gb 1.2gb ... 색인 이름만 가져오고 싶다면 어떻게 호출해야 할까? 설명 /_cat/indices?v 위와 같이 호출하면 아래처럼 결과가 나온다. health status index uuid pri rep docs.count docs.deleted store.size pri.st..
-
Variance 문제scala/basic 2021. 10. 22. 21:30
scala 에서 이해하기 가장 어려운 부분 중 하나가 Variance 일 것이다. Variance 를 이해 했다면 다음 문제를 풀어보자. 문제1 아래와 같이 정의했을 때 trait Sum[+A, +B] { def flatMap[C](f: B => Sum[A, C]): Sum[A, C] = ??? } 다음과 같은 에러 메시지를 보게 될 것이다. error: covariant type A occurs in contravariant position in type B => Sum[A,C] of value f 이를 해결하려면 어디를 수정해야 할까? 아래와 같이 작성하면 된다. (Why?) trait Sum[+A, +B] { def flatMap[T >: A, C](f: B => Sum[T, C]): Sum[T, ..
-
docker container 에서 zombie 프로세스 발생 문제docker 2021. 10. 14. 12:05
문제 jupyterhub 를 docker 로 실행해 서비스를 제공했다. 각각의 사용자들이 notebook 을 닫지 않은채 single-user server 를 재시작할 경우 zombie 프로세스가 발생했다. bare metal 장비에 직접 jupyterhub 를 설치했으면 발생하지 않았을 문제인데, docker 를 사용해서 발생한 문제였다. 왜 그럴까? 설명 jupyterhub 는 user 마다 single-user server process 가 실행된다. 그리고 user 가 notebook 을 실행할 때 마다 single-user server process 의 child process 가 실행된다. 결국 아래와 같은 구조가 된다. jupyterhub L single-user server L notebo..