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
private object Validations { | |
trait NotEmpty[F[_], T] { | |
def validate(field: F[T]): Boolean | |
} | |
implicit def optionNotEmpty[T]: NotEmpty[Option, T] = field => field.isDefined | |
implicit def listNotEmpty[T]: NotEmpty[List, T] = field => field.nonEmpty | |
def notEmpty[F[_], T](field: F[T])(implicit ev: NotEmpty[F, T]): Boolean = ev.validate(field) | |
} |
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
Stream<Integer> xs = Stream.of(5, 3, 7, 3, 2, 7); | |
final List<Integer> range = IntStream.range(0, 100).boxed().collect(toList()); | |
final List<List<Integer>> result = | |
range | |
.parallelStream() | |
.map(e -> xs.sorted().collect(toList())) | |
.collect(toList()); |
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 me.lavando.user.api.features | |
import scala.concurrent.duration._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.{Await, Future} | |
import scala.util.Failure | |
/** | |
* @author Gabriel Francisco <[email protected]> | |
*/ |
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 loggedRequest(magnet: LoggingMagnet[String ⇒ Unit]): Directive0 = extractRequestContext.flatMap { ctx ⇒ | |
val timer = Timer.start | |
mapRouteResult { | |
case result: Complete => | |
//extracting request and complete route result here | |
result | |
case result: Rejected => | |
//extracting request and rejected route result here | |
result |
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
public static void main(String[] args) { | |
class Player { | |
Integer id; | |
String team; | |
public Player(Integer id, String team) { | |
this.id = id; | |
this.team = team; | |
} |
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 java.util.{Date, UUID} | |
import InMemoryEventStore._ | |
import scala.language.dynamics | |
/** | |
* @author Gabriel Francisco <[email protected]> | |
*/ | |
class DynamicData(var data: Map[String, Any] = Map()) extends Dynamic { |
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
=========================================================================== | |
HTTP GET /frodo/api/products/58ac762ce051672d61af1648/events | |
[Header] Host -> 127.0.0.1:33324 | |
=========================================================================== | |
2017-02-21T14:17:36.968-0300 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58794 #10 (10 connections now open) | |
[mongod output] 2017-02-21 17:17:36 [Thread-11] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:10, serverValue:10}] to localhost:27017 | |
--------------------------------------------------------------------------- | |
[Status] Status(200) | |
[Header] Content-Type -> application/json; charset=utf-8 | |
[Header] Content-Length -> 626 |
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 com.fasterxml.jackson.databind.ObjectMapper | |
import com.fasterxml.jackson.module.scala.DefaultScalaModule | |
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper | |
import spark.ResponseTransformer | |
import spark.Spark._ | |
object MainClass { | |
val objectMapper = new ObjectMapper with ScalaObjectMapper | |
objectMapper.registerModule(DefaultScalaModule) | |
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
object BSTApp extends App { | |
def maxValue(head: Node, actual: Int = Int.MinValue): Int = head match { | |
case Node(v, null, null) => if (actual > v) actual else v | |
case Node(v, l, null) => maxValue(l, if (actual > v) actual else v) | |
case Node(v, null, r) => maxValue(r, if (actual > v) actual else v) | |
case Node(v, l, r) => | |
val maxLeft = maxValue(r, if (actual > v) actual else v) | |
val maxRight = maxValue(l, if (actual > v) actual else v) | |
if (maxLeft > maxRight) maxLeft else maxRight |
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 Transaction(transactionType: String) | |
trait Payment { | |
def pay(transaction: Transaction): Transaction | |
} | |
class MasterCard extends Payment { | |
override def pay(transaction: Transaction): Transaction = { | |
println("paid with master") | |
transaction |