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.mgl.digital.dataservices.utils | |
import com.datastax.driver.core._ | |
class PreparedStatementBuilder(session: Session) { | |
private var statementCache: Map[String, PreparedStatement] = Map() | |
def insertInto(table: String): Insert = |
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
{sealed trait Tree | |
case object EmptyTree extends Tree | |
case class Leaf(label: String, popularity: Double) extends Tree | |
case class Node(popularity: Double, left: Tree, right: Tree) extends Tree | |
implicit val treeOrdering = new Ordering[Tree] { | |
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
/** | |
* Like Future.sequence but but limits the parallelism to only process so many futures at once. | |
* Useful if you have lots of future operations but dont want to overload something with too many at once. | |
*/ | |
def gatherUnordered[A, B](parallelism: Int, | |
xs: Seq[A])(fn: A => Future[B])(implicit ex: ExecutionContext): Future[Seq[B]] = { | |
def go(todo: Seq[A], inprogress: Seq[Future[B]], acc: Seq[B]): Future[Seq[B]] = { | |
if (inprogress.size < parallelism && todo.nonEmpty) { | |
val numToAdd = parallelism - inprogress.size | |
val (toStart, stillTodo) = todo.splitAt(numToAdd) |
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 $ivy.`net.databinder.dispatch::dispatch-core:0.13.1` | |
import scala.concurrent.ExecutionContext | |
import scala.concurrent.Future | |
import dispatch._, Defaults._ | |
val svc = url("http://httpbin.org/ip") | |
def get() = Http.default(svc OK as.String) | |
def getAndTime(idx: Int) = { |
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
/* | |
* traverse cancellable takes an Array of promise's running them in parallel returning a single promise of their result and cancel function. | |
* | |
* @inputThunks Array[() => Promise[A]] an array of promises not yet started, thunks () => Promise | |
* @returns Object { | |
* promise: Promise[Array[A]] | |
* cancel: Function() to cancel | |
* } | |
*/ | |
export function traverseCancellable(inputThunks) { |
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
/* | |
* gather unordered takes an Array of promise's running them in parallel returning a single promise of their result and cancel function. | |
* | |
* If a error is encountered the first error will be returned, remaining unordered thunks will not be executed. | |
* | |
* @inputThunks Array[() => Promise[A]] an array of promises not yet started, thunks () => Promise | |
* @parallism number of promises to run at once | |
* @returns Object { | |
* promise: Promise[Array[A]] | |
* cancel: Function() to cancel |
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
# results from https://github.com/stephennancekivell/circe-argonaut-compile-times | |
# 100 case classes with up to 15 values | |
play-json 2.12 | |
23 | |
19 | |
play-json.topic 2.12 | |
17 | |
20 | |
circe 2.12 |
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
val skip = Set.empty[String] | |
import java.util.{Map => JMap, List => JList} | |
def diff(a: JMap[String, Any], b: JMap[String, Any], prefix: String = ""): Unit = { | |
(a.keySet().asScala.toSet ++ b.keySet().asScala.toSet).filterNot(skip.contains).foreach { key => | |
val prefixKey = s"$prefix.$key" | |
(Option(a.get(key)), Option(b.get(key))) match { | |
case (Some(av), Some(bv)) if av.isInstanceOf[JMap[String, Any]] && bv.isInstanceOf[JMap[String, Any]] => | |
diff(av.asInstanceOf[JMap[String, Any]], bv.asInstanceOf[JMap[String, Any]], prefixKey) |
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
terraform apply | |
An execution plan has been generated and is shown below. | |
Resource actions are indicated with the following symbols: | |
+ create | |
Terraform will perform the following actions: | |
# docker_container.nginx will be created | |
+ resource "docker_container" "nginx" { |
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
terraform apply | |
2020/02/18 15:58:02 [INFO] Terraform version: 0.12.13 | |
2020/02/18 15:58:02 [INFO] Go runtime version: go1.12.9 | |
2020/02/18 15:58:02 [INFO] CLI args: []string{"/usr/local/Cellar/tfenv/1.0.2/versions/0.12.13/terraform", "apply"} | |
2020/02/18 15:58:02 [DEBUG] Attempting to open CLI config file: /Users/stephen/.terraformrc | |
2020/02/18 15:58:02 [DEBUG] File doesn't exist, but doesn't need to. Ignoring. | |
2020/02/18 15:58:02 [INFO] CLI command args: []string{"apply"} | |
2020/02/18 15:58:02 [DEBUG] checking for provider in "." | |
2020/02/18 15:58:02 [DEBUG] checking for provider in "/usr/local/Cellar/tfenv/1.0.2/versions/0.12.13" | |
2020/02/18 15:58:02 [DEBUG] checking for provider in ".terraform/plugins/darwin_amd64" |