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.Properties | |
import akka.actor.{Actor, ActorLogging, Props} | |
import akka.event.LoggingReceive | |
import com.typesafe.config.{Config, ConfigFactory} | |
import KafkaProducerActor.KafkaMessage | |
import kafka.common.FailedToSendMessageException | |
import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord} | |
import scala.concurrent.duration._ |
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 scala.annotation.tailrec | |
import scala.collection.immutable.ListMap | |
object WeightSorting extends App { | |
def sortWeight(str: String): String = { | |
val map = str | |
.split(" ") //split by empty space | |
.map(s => (sumTailRecursive(s), s)) //let's create a tuple of (weight, string) | |
.groupBy(_._1) //group it by weight |
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.stream._ | |
import akka.stream.stage._ | |
import com.amazonaws.handlers.AsyncHandler | |
import com.amazonaws.services.kinesis.AmazonKinesisAsync | |
import com.amazonaws.services.kinesis.model.{PutRecordsRequest, PutRecordsRequestEntry, PutRecordsResult} | |
import scala.collection.JavaConverters._ | |
class AwsKinesisFlowStage(streamName: String, kinesisClient: AmazonKinesisAsync) extends GraphStage[FlowShape[Seq[PutRecordsRequestEntry], PutRecordsResult]] { |
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 AddressRepository extends DBConnection { | |
val table = TableQuery[AddressModel] | |
def search(filter: Address): Future[Seq[Address]] = { | |
@tailrec | |
def recursive(queryMap: Map[String, String], queryAccum: Query[AddressModel, Address, Seq]): Query[AddressModel, Address, Seq] = { | |
if (queryMap.isEmpty) queryAccum else { | |
val key = queryMap.head._1 | |
val value = queryMap.head._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
case class Address(state: Option[String], city: Option[String], neighborhood: Option[String], street: Option[String], streetNumber: Option[String]) { | |
def toMap(): Map[String, String] = { | |
Map( | |
"state" -> this.state, | |
"city" -> this.city, | |
"neighborhood" -> this.neighborhood, | |
"street" -> this.street, | |
"streetNumber" -> this.streetNumber | |
).filter(_._2.isDefined).mapValues(_.get) | |
} |
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 Predicate createAdvancedSearchQuery(Long maxPrice, Long minPrice, Integer beds, Integer baths, String province) { | |
QProperty property = QProperty.property; | |
BooleanBuilder booleanBuilder = new BooleanBuilder(); | |
if(maxPrice != null && minPrice != null) { | |
booleanBuilder.and(property.price.between(minPrice, maxPrice)); | |
} else if (maxPrice != null) { | |
booleanBuilder.and(property.price.loe(maxPrice)); | |
} else if (minPrice != null) { |
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
//imports | |
object MyBackPressureTest extends App { | |
implicit val system = ActorSystem() | |
implicit val materializer = ActorMaterializer() | |
val addresses = List(Address...) //a list of some addresses | |
val createRequestFlow = Flow[Address].map { address => |
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 slick.driver.MySQLDriver.simple._ | |
import scala.slick.collection.heterogenous._ | |
import scala.slick.collection.heterogenous.syntax._ | |
import scala.slick.jdbc._ | |
// This is the large case class we are mapping -- 25 string fields: | |
case class BigData( | |
field1: String, | |
field2: String, | |
field3: String, |
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.vivareal.columbus | |
import java.util.concurrent.CountDownLatch | |
import akka.actor.{Actor, ActorLogging, ActorRef, ActorSystem, Props} | |
import akka.routing.RoundRobinPool | |
import com.vivareal.columbus.infrastructure.ActorCreation | |
import scala.concurrent.duration.Duration |
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.UUID | |
import akka.NotUsed | |
import akka.actor.{ActorRef, ActorSystem} | |
import akka.stream._ | |
import akka.stream.scaladsl.{Balance, Flow, GraphDSL, Sink, Source} | |
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain | |
import com.amazonaws.services.sqs.AmazonSQSAsyncClient | |
import com.amazonaws.services.sqs.model.Message | |
import com.github.dwhjames.awswrap.sqs.AmazonSQSScalaClient |
NewerOlder