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
| package services | |
| import play.api.mvc.RequestHeader | |
| object ConcatService { | |
| object PublishPage { | |
| val name = "publish-page.js" | |
| val files = Vector("javascripts/vendor/sidr.js", "javascripts/vendor/plugins.js", "javascripts/entry/entry.js", "javascripts/entry/entry-stats.js") | |
| def path(implicit context: AssetContext, rh: RequestHeader) = AssetService.at(name) |
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
| package services | |
| import play.api.mvc.RequestHeader | |
| object ConcatService { | |
| object PublishPage { | |
| val name = "publish-page.js" | |
| val files = Vector("javascripts/vendor/sidr.js", "javascripts/vendor/plugins.js", "javascripts/entry/entry.js", "javascripts/entry/entry-stats.js") | |
| def path(implicit context: AssetContext, rh: RequestHeader) = AssetService.at(name) |
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
| implicit class UUIDExtensions(wrapped: UUID) { | |
| def pretty: String = formatUUID(wrapped) | |
| def toBytes: Array[Byte] = uuidToBytes(wrapped) | |
| } |
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
| def safely[T](f: PartialFunction[Throwable, T]): PartialFunction[Throwable, T] = new PartialFunction[Throwable, T] { | |
| override def isDefinedAt(x: Throwable): Boolean = NonFatal(x) && f.isDefinedAt(x) | |
| override def apply(v1: Throwable): T = f(v1) | |
| } | |
| try throw new InvalidParameterException("Test") | |
| catch safely { | |
| case exc => exc.printStackTrace() | |
| } |
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
| package mapops { | |
| implicit class DayOneMapOps[A, +B](wrapped: Map[A, B]) { | |
| // Scalaz has `mapKeys` to just change keys | |
| // Scala has `mapValues` to just change values | |
| // Scala has `transform` to just change values but provides key as a parameter | |
| /** | |
| * This function transforms all the keys and values of mappings contained in this map with function `f`. |
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
| scala> val mayBeLong: Option[Long] = Option(null: java.lang.Long) | |
| java.lang.NullPointerException | |
| at scala.Predef$.Long2long(Predef.scala:358) | |
| ... 33 elided | |
| scala> val mayBeLong: Option[Long] = Option(null: java.lang.Long).flatMap(Option.apply _) | |
| <console>:7: error: type mismatch; | |
| found : java.lang.Long => Option[java.lang.Long] | |
| required: java.lang.Long => Option[scala.Long] | |
| val mayBeLong: Option[Long] = Option(null: java.lang.Long).flatMap(Option.apply _) |
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
| [ | |
| "Red", | |
| "Blue", | |
| "Gray or Grey", | |
| "DarkBlue", | |
| "Black", | |
| "Orange", | |
| "Purple", | |
| "Brown", | |
| "Maroon", |
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
| scala> Array(1).hashCode | |
| res16: Int = 357917741 | |
| scala> Array(1).hashCode | |
| res17: Int = 1064821544 | |
| scala> Seq(1).hashCode | |
| res18: Int = 1945410391 | |
| scala> Seq(1).hashCode |
This file has been truncated, but you can view the full file.
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
| !function(){function e(e){console.log(e)}var t=["Genesis 1:1 In the beginning God created the heaven and the earth.","Genesis 1:2 And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.","Genesis 1:3 And God said, Let there be light: and there was light.","Genesis 1:4 And God saw the light, that it was good: and God divided the light from the darkness.","Genesis 1:5 And God called the light Day, and the darkness he called Night. And the evening and the morning were the first day.","Genesis 1:6 And God said, Let there be a firmament in the midst of the waters, and let it divide the waters from the waters.","Genesis 1:7 And God made the firmament, and divided the waters which were under the firmament from the waters which were above the firmament: and it was so.","Genesis 1:8 And God called the firmament Heaven. And the evening and the morning were the second day.","Genesis 1:9 And God said, Let the waters under the heaven be |
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
| @scala.annotation.tailrec | |
| def fact(n: Int, acc: BigInt = 1): BigInt = | |
| if(n < 0) throw new Exception("n must be >= 0") | |
| else if (n == 0) acc | |
| else fact(n - 1, acc * n) |