Skip to content

Instantly share code, notes, and snippets.

type Aux[T, Repr0] = Generic[T] { type Repr = Repr0 }
case class Simple(number: Int, working: Boolean, someText: String)
val s = Simple(2, true, "hello")
// s: Simple = Simple(2,true,hello)
val sGen = Generic[Simple]
// sGen: shapeless.Generic[Simple]{type Repr = Int :: Boolean :: String :: shapeless.HNil} = anon$macro$4$1@215c6699
trait Generic[T] extends Serializable {
/** The generic representation type for {T}, which will be composed of {Coproduct} and {HList} types */
type Repr
/** Convert an instance of the concrete type to the generic value representation */
def to(t : T) : Repr
/** Convert an instance of the generic representation to an instance of the concrete type */
def from(r : Repr) : T
}
implicit def caseClassToGenerator[A, Repr <: HList](
implicit generic: LabelledGeneric.Aux[A, Repr],
gen: ComponentGenerator[Repr],
reactComponent: ReactComponentGenerator[A]
): ComponentGenerator[A] =
new ComponentGenerator[A] {
override def generate = reactComponent.generate(gen.generate)
}
{
content: "RT @HKane: What a feeling to score a winner for @England at the @FIFAWorldCup. Loved it! No less than we deserved. 🦁🦁🦁 #ThreeLions #ENG #Wo…",
author: "Ogunlola Olamide",
sentimentScore: 63,
mentionedCountries: [
{
England: {
name: "England"
}
}
{
content: "RT @georgeseara: Sooo epic and an honour to be a part of.. @shawnmendes x @portugal ⚽️ Força Portugal!! 🇵🇹❤️ #WorldCup #Portugal #ShawnMend…",
author: "Hanslei Mendes",
sentimentScore: 83,
mentionedCountries: [
{
Portugal: {
name: "Portugal"
}
}
{
status: "200 OK",
data: {
Poland: {
count: 8,
sentimentCount: 8,
averageSentiment: 0
},
Egypt: {
count: 14,
class StatisticsActor extends Actor {
import StatisticsActor._
self ! Init
def receive: Receive = {
case Init => context become ready(Map[String, Stats]())
}
def ready(stats: Map[String, Stats]): Receive = {
object AwsSentimentService extends SentimentService {
override def getSentiment(s: String): Future[Sentiment] = {
val awsCreds = DefaultAWSCredentialsProviderChain.getInstance
val comprehendClient = AmazonComprehendClientBuilder.standard.withCredentials(awsCreds).withRegion("eu-west-1").build
Future {
val req = new DetectSentimentRequest().withText(s).withLanguageCode("en")
val result = comprehendClient.detectSentiment(req)
println(result)
Sentiment(result.getSentiment, getSentimentScore(result))
class TweetConsumerService extends LazyLogging {
this: LatestUpdateModule with SentimentModule =>
def start = {
logger.info( "starting streaming" )
val client = TwitterStreamingClient()
client.filterStatuses(stall_warnings = true, tracks = Seq("Russia2018", "WorldCup", "FIFA"))(handleTweet)
}
def handleTweet: PartialFunction[StreamingMessage, Unit] = {