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
class EndlessIterator[T](iterable: Iterable[T]) extends Iterator[T] { | |
assert(iterable.nonEmpty, "iterable is empty") | |
private var _iterator = iterable.iterator | |
private def iterator = | |
if (_iterator.hasNext) _iterator | |
else { | |
_iterator = iterable.iterator | |
_iterator |
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
{ | |
"type": "object", | |
"$schema": "http://json-schema.org/draft-03/schema", | |
"id": "#", | |
"title":"Child", | |
"properties": { | |
"name": { | |
"type": "string", | |
"id": "name", | |
"required": true |
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 cqrs | |
import scala.reflect.ClassTag | |
object api { | |
type Identifier = String | |
def newIdentifier: Identifier = java.util.UUID.randomUUID().toString | |
type Revision = Long | |
val initialRevision: Revision = 0L |
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.util.ByteString | |
import ByteOrder.{BIG_ENDIAN, LITTLE_ENDIAN} | |
def putLongPart(order: ByteOrder) = ByteString.newBuilder.putLongPart(123, 4)(order).result() | |
require(putLongPart(BIG_ENDIAN) != putLongPart(LITTLE_ENDIAN)) |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectCodeStyleSettingsManager"> | |
<option name="PER_PROJECT_SETTINGS"> | |
<value> | |
<option name="USE_SAME_INDENTS" value="true" /> | |
<option name="IGNORE_SAME_INDENTS_FOR_LANGUAGES" value="true" /> | |
<option name="OTHER_INDENT_OPTIONS"> | |
<value> | |
<option name="INDENT_SIZE" value="2" /> |
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
lazy val flyway = new Flyway { | |
setDataSource(dataSource) | |
} | |
def migrateToLatestDbVersion() { | |
try flyway.migrate() catch { | |
case e: FlywayException if e.getMessage.startsWith("Unable to check whether schema") => | |
flyway.init() | |
flyway.migrate() | |
} |
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
case class Coordinates(x: Double, y: Double) | |
object HaversineDistance { | |
def apply(a: Coordinates, b: Coordinates): Double = { | |
val deltaLat = math.toRadians(b.x - a.x) | |
val deltaLong = math.toRadians(b.y - a.y) | |
val x = math.pow(math.sin(deltaLat / 2), 2) + math.cos(math.toRadians(a.x)) * math.cos(math.toRadians(b.x)) * math.pow(math.sin(deltaLong / 2), 2) | |
val greatCircleDistance = 2 * math.atan2(math.sqrt(x), math.sqrt(1 - x)) | |
3958.761 * greatCircleDistance | |
} |
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
lazy val dbCache: Option[Cache] = ??? | |
lazy val realCache: scala.concurrent.Future[Cache] = ??? | |
def cache: Option[Cache] = { | |
realCache.value match { | |
case Some(Success(x)) => Some(x) | |
case None => dbCache | |
case Some(Failure(error)) => | |
log.error(error) | |
dbCache |
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
# Maven | |
target | |
# Idea | |
.idea/ | |
*.iml | |
*.ipr | |
#JRebel | |
rebel.xml |
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 com.evolutiongaming.serialization | |
import java.nio.charset.Charset | |
import akka.serialization.SerializerWithStringManifest | |
import scala.util.control.NoStackTrace | |
class BrokenSerializer extends SerializerWithStringManifest { |