This file contains hidden or 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.apache.commons.math3.stat.descriptive.DescriptiveStatistics | |
import org.scalatest.{FlatSpec, Matchers} | |
import scala.io.Source | |
class MobileResponseTimeSpec extends FlatSpec with Matchers { | |
val FILE_NAME = "/Users/msbaek/Downloads/res_time.txt" | |
val NINETY = 90.0 | |
val THREE_SECONDS = 3.0 | |
val TEN_SECONDS = 10.0 |
This file contains hidden or 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 models.{DB, SdssRecord} | |
import org.joda.time.LocalDate | |
import org.specs2.mutable.Specification | |
import play.api.libs.ws.{WS, WSResponse} | |
import play.api.test.WithApplication | |
import scala.concurrent.Future | |
import scala.util.{Failure, Success} | |
import scala.util.matching.Regex.Match |
This file contains hidden or 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 akka.actor.ActorSystem | |
import models.{DB, SdssRecord} | |
import org.joda.time.LocalDate | |
import org.specs2.mutable.Specification | |
import play.api.libs.ws.{WS, WSResponse} | |
import play.api.test.WithApplication | |
import spray.http.{HttpRequest, HttpResponse} | |
import akka.actor.ActorSystem | |
import spray.http.{HttpRequest, HttpResponse} |
This file contains hidden or 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 | |
object crawler extends App { | |
val DAUM_URL = "http://m.search.daum.net/search?w=tot&q=%s" | |
val URL_EXPRESSION = """http://[A-Za-z0-9-_]+.[A-Za-z0-9-_:%&?/.=]+""".r | |
val queries = Seq("이효리", "날씨", "다음") | |
(queries map getHttp).flatten foreach println |
This file contains hidden or 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
/** ********************************** | |
* -> "in" generator | |
* ***********************************/ | |
for (arg <- List("one", "two", "three")) | |
println(arg) | |
/** ********************************** | |
* ::: 리스트를 붙일 때 | |
* **********************************/ | |
List(1, 2) ::: List(3, 4, 5) |
This file contains hidden or 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
// the empty list | |
List() | |
Nil | |
// 원소를 갖는 리스트 생성 | |
List("Cool", "tools", "rule") | |
// 3개의 값으로 새로운 List 생성 | |
val thrill = "Will" :: "fill" :: "until" :: Nil |
This file contains hidden or 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
// Listing 3.11 Printing formatted character counts for the lines of a url | |
import scala.io.Source | |
def widthOfLength(s: String) = s.length.toString.length | |
val lines = Source.fromURL("https://gist.githubusercontent.com/msbaek/e830f66f5165fbbb844e/raw/d48da60bb3479f5f708367e677a492462afcf66e/gistfile1.scala", "utf8").getLines().toList | |
val longestLine = lines.reduceLeft( | |
(a, b) => if(a.length > b.length) a else b | |
) | |
val maxWidth = widthOfLength(longestLine) |
This file contains hidden or 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.junit.Test; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
public class LoggingTest { | |
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |
@Test | |
public void foo() { | |
logger.error("error for {} message for {}", 123, "hello"); |
This file contains hidden or 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
/** | |
* foldLeft | |
*/ | |
List(1, 2, 3, 4, 5).foldLeft(0) { (totalSofar, current) => | |
totalSofar + current | |
} | |
List(1, 2, 3, 4, 5).foldLeft(List[Int]())((b, a) => a :: b) | |
val rr : Range = 1 to 10 | |
rr.foldLeft(0)(_ + _) // sum | |
rr.foldLeft(1)(_ * _) // product |
This file contains hidden or 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
/** | |
* partial function | |
* 타입 A의 모든 값에 대해서 정의되지 않은 부분 함수 <--> 전체함수 | |
*/ | |
val fraction = new PartialFunction[Int, Int] { | |
override def isDefinedAt(x: Int): Boolean = x != 0 | |
override def apply(v1: Int): Int = 42 / v1 | |
} |
OlderNewer