forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.scala
72 lines (58 loc) · 2.1 KB
/
package.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import ornicar.scalalib._
import play.api.libs.json.JsValue
import play.api.libs.concurrent.Promise
import play.api.libs.iteratee.{ Iteratee, Enumerator }
import play.api.libs.iteratee.Concurrent.Channel
import play.api.Play.current
import com.novus.salat.{ Context, TypeHintFrequency, StringTypeHintStrategy }
import com.mongodb.casbah.commons.conversions.scala.RegisterJodaTimeConversionHelpers
import scalaz.effects.{ io, IO }
package object lila
extends OrnicarValidation
with OrnicarCommon
with OrnicarRegex
with OrnicarIO
with scalaz.Identitys
with scalaz.NonEmptyLists
with scalaz.Strings
with scalaz.Lists
with scalaz.Booleans {
type JsChannel = Channel[JsValue]
type JsEnumerator = Enumerator[JsValue]
type SocketPromise = Promise[(Iteratee[JsValue, _], JsEnumerator)]
// custom salat context
implicit val customSalatContext = new Context {
val name = "Lila Context"
override val typeHintStrategy = StringTypeHintStrategy(
when = TypeHintFrequency.Never)
}
RegisterJodaTimeConversionHelpers()
def !![A](msg: String) = msg.failNel[A]
def nowMillis: Double = System.currentTimeMillis
def nowSeconds: Int = (nowMillis / 1000).toInt
implicit def richerMap[A, B](m: Map[A, B]) = new {
def +?(bp: (Boolean, (A, B))): Map[A, B] = if (bp._1) m + bp._2 else m
}
def parseIntOption(str: String): Option[Int] = try {
Some(java.lang.Integer.parseInt(str))
}
catch {
case e: NumberFormatException ⇒ None
}
def parseFloatOption(str: String): Option[Float] = try {
Some(java.lang.Float.parseFloat(str))
}
catch {
case e: NumberFormatException ⇒ None
}
def intBox(in: Range.Inclusive)(v: Int): Int =
math.max(in.start, math.min(v, in.end))
def floatBox(in: Range.Inclusive)(v: Float): Float =
math.max(in.start, math.min(v, in.end))
def printToFile(f: java.io.File)(op: java.io.PrintWriter ⇒ Unit): IO[Unit] = io {
val p = new java.io.PrintWriter(f)
try { op(p) } finally { p.close() }
}
def printToFile(f: String)(op: java.io.PrintWriter ⇒ Unit): IO[Unit] =
printToFile(new java.io.File(f))(op)
}