This file contains 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 DatesTest extends FreeSpec with Matchers{ | |
import java.util.Date | |
import scala.concurrent.duration._ | |
implicit class RichDate(d:Date){ | |
def -(duration: Duration) = new Date(d.getTime - duration.toMillis) | |
def +(duration: Duration) = new Date(d.getTime + duration.toMillis) | |
def as(name: String) = new Date(d.getTime){ | |
override def toString = s"[$name]" | |
} |
This file contains 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
trait ReflectionSugars{ | |
import scala.reflect.runtime.{universe => ru} | |
private lazy val universeMirror = ru.runtimeMirror(getClass.getClassLoader) | |
def companionOf[T](implicit tt: ru.TypeTag[T]) = { | |
val companionMirror = universeMirror.reflectModule(ru.typeOf[T].typeSymbol.companionSymbol.asModule) | |
companionMirror.instance | |
} | |
} |
This file contains 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 util.parsing.json.JSON | |
import io.Source | |
import scala.language.dynamics | |
object Example extends App{ | |
val json = """{ | |
"name" : "Adam Slodowy", | |
"active": "true", | |
"roles" : [ "teacher", "admin" ], |
This file contains 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 concurrent.{Await, ExecutionContext, Future} | |
import java.net.{HttpURLConnection, URL} | |
import io.Source | |
import concurrent.duration.FiniteDuration | |
case class HttpResponse(code : Int, body: String, headers: Map[String, List[String]]) | |
case class RequestBody(body: String, contentType: String = "text/plain") | |
object RequestBody{ |
This file contains 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
if (clientConfiguration.getMaxErrorRetry() == ClientConfiguration.DEFAULT_MAX_RETRIES) { | |
log.debug("Overriding default max error retry value to: " + 10); | |
clientConfiguration.setMaxErrorRetry(10); | |
} |
This file contains 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 [cent, idx, sizes, distortion]=km(data, k, maxIter) | |
N = size(data,1); | |
COL = size(data,2); | |
cent = data(randperm(N)(1:k), : ); | |
#cent = rand(k, COL) * 0.5 + 0.5 | |
for iter = 1 : maxIter | |
fprintf("Iteration %d\n", iter); | |
dist = []; |
This file contains 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.camel.{Consumer, CamelMessage} | |
import akka.actor.{Props, ActorSystem} | |
import akka.util.Timeout | |
import akka.util.duration._ | |
import akka.pattern.ask | |
import scaladays2012.{Email, EmailerConfig, Emailer} | |
class HttpConsumerExample extends Consumer{ | |
def endpointUri = "jetty://http://0.0.0.0:1111/demo" |
This file contains 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 annotation.tailrec | |
import java.util.concurrent.atomic.AtomicReference | |
object Atomic { | |
def apply[T]( obj : T) = new Atomic(new AtomicReference(obj)) | |
implicit def toAtomic[T]( ref : AtomicReference[T]) : Atomic[T] = new Atomic(ref) | |
} | |
class Atomic[T](val atomic : AtomicReference[T]) { | |
@tailrec |
This file contains 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.XXX.connector | |
import testdsl.connector.ConnectorAccountDsl | |
import testdsl.facebook.FacebookAccountDsl | |
import util.Random | |
import akka.actor.{Scheduler, Actor} | |
import java.util.concurrent.TimeUnit | |
import org.junit.Test |
This file contains 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
object Try { | |
/** | |
* Tries to execute body. | |
* | |
* Example below tries to start template and if it's unsuccessful it stops context. | |
* <pre> Try(template.start()) otherwise context.stop() </pre> | |
* | |
* @param body block of code to execute. | |
* @return Ok, if no exception is thrown by body. |
NewerOlder