전체 글
-
apache poi 를 사용해 scala 에서 Excel 파일 읽기scala/basic 2021. 10. 14. 11:17
def main(args: Array[String]): Unit = { val rows = readSheet[MyModel]("c:/work/input.xlsx", "평가 항목", true) println(rows) } 문제 apache poi 를 사용해 Excel 파일을 읽어보자. apache poi 는 자바 라이브러리지만 스칼라 스타일로 코딩해 보도록 한다. 코드 일반적으로 사용할 수 있도록 아래처럼 Generic 한 util 을 작성한다. import org.apache.poi.openxml4j.opc.OPCPackage import org.apache.poi.ss.usermodel.{Row, Workbook} import org.apache.poi.xssf.usermodel.XSSFWorkbook..
-
프로세스가 실행 중인지 체크 후 실행하기bash 2021. 10. 14. 11:15
문제 프로세스가 이미 실행 중이면 실행하지 않고, 실행중이지 않으면 실행하는 스크립트를 작성한다. (스크립트를 반복 실행 하더라도 프로세스가 중복 실행되지 않도록 한다.) 프로세스가 실행될 때 PID 를 파일로 기록하고, kill -0 PID 로 체크 하도록 한다. 코드 #!/bin/bash ulimit -c unlimited BIN_DIR=`dirname "$0"` BASE_DIR=`cd "$BIN_DIR"; cd ..; pwd` LOG_DIR=$BASE_DIR/logs PID_FILE=$BASE_DIR/application.pid # PID_FILE 이 존재하고, 해당 PID 로 running 중이면 application 을 실행하지 않고 exit 한다. if [ -f $PID_FILE ]; then..
-
gitbook 배포 하기gitbook 2021. 10. 13. 13:58
문제 markdown 으로 문서를 작성후 github pages 에 배포하도록 한다. master branch 가 checkout 된 상태에서 gitbook build 를 하면 생성되는 _book 디렉토리를 gh-pages branch 에 docs 로 이름을 변경 후 덮어쓰도록 한다. 코드 #!/bin/bash # gitbook 이 설치된 장비에서 # master branch 가 checkout 된 상태에서 repo_dir=`dirname "$0"` cd $repo_dir GH_PAGES_TEMP_DIR="gh-pages-temp-branch" rm -rf ./_book $GH_PAGES_TEMP_DIR gitbook build || exit $? git clone -b gh-pages --single-..
-
실행되는 스크립트로 부터 프로젝트 홈의 절대 경로 알아내기bash 2021. 10. 13. 11:17
문제 디렉토리 구조가 아래와 같고, /home/windbird/work/project/bin/run.sh 가 있을 때 $pwd /home/windbird $tree work/ work/ └── project ├── bin │ └── run.sh ├── conf │ └── server.conf └── logs cd /home/windbird/; sh work/project/bin/run.sh 로 실행되거나 cd /home/windbird/work; sh project/bin/run.sh 로 실행되든지 간에 항상 프로젝트 홈인 /home/windbird/work/project 가 출력되도록 run.sh 스크립트를 작성해 보자 코드 #!/bin/bash bin_dir=`dirname "$0"` home_dir..
-
Functional Effect 의 다양한 합성(composition)zio/zio-prelude 2021. 10. 10. 22:49
문제 아래와 같이 A, B, C, D 를 정의할 때, 다양하게 합성해 보자. def A: Option[String] = { println("A") Some("A") } def B: Option[Int] = { println("B") Some(1) } def C: Option[String] = { println("C") None } def D: Option[Int] = { println("D") None } 코드 Monad 합성 val monad: Option[(String, String)] = for { c "C is empty") def aValid: Validation[String, String] = Validation.fromOption(A).mapError(_ => "A is empty") val..
-
ZIO prelude 의 State Monadzio/zio-prelude 2021. 9. 26. 23:54
문제 Scala State Monad 의 문제를 zio-prelude 의 State Monad(ZPure) 를 사용해 구현하라. 코드 import zio.prelude.State object GolfDistance { def swing(n: Int): State[Int, Int] = State.modify(s => (s + n, s + n)) def main(args: Array[String]): Unit = { val distance: State[Int, Int] = for { _
-
NewTypes 과 Equal 을 활용한 객체 비교zio/zio-prelude 2021. 9. 23. 23:25
문제 다음과 같이 Site, bookSite, newsSite 를 정의할 때 final case class Site(domain: String, url: String) val bookSite = Site("naver.com", "http://book.naver.com") val newsSite = Site("naver.com", "http://news.naver.com") bookSite 와 newsSite 를 domain 기준으로 비교하면 같다. url 기준으로 비교하면 다르다. domain 과 url 기준으로 각각 비교하는 method 를 아래처럼 추가할 수 있지만 final case class Site(domain: String, url: String) { def equalByDomain(other..
-
href 값으로 empty 지정하기web/scalajs 2021. 9. 1. 09:48
문제 SPA(Single Page Application) 으로 만들면서, href 값으로 empty 를 지정하고 싶다. 그런데 아래와 같이 할 경우 error 가 발생한다. link 혹은 '#' 값으로 할 경우 browser url '#' 이 추가된다. link 코드 link 참고: https://stackoverflow.com/questions/134845/which-href-value-should-i-use-for-javascript-links-or-javascriptvoid0