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 NumericColumns(TransformerMixin): | |
def __init__(self): | |
self.columns = [column names] | |
def fit(self, X): | |
cols = [] | |
for col in self.columns: | |
try: | |
X[col].astype('float') |
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.http.scaladsl.server.Directives._ | |
import akka.http.scaladsl.server.Route | |
import akka.http.scaladsl.Http | |
import akka.stream.ActorMaterializer | |
import scala.io.StdIn | |
object WebServer extends App { | |
// implicit values required by the server machinery | |
implicit val actorSystem = akka.actor.ActorSystem("messaging-actorsystem") |
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.http.scaladsl.server.Directives._ | |
import akka.http.scaladsl.server.Route | |
import akka.http.scaladsl.Http | |
import akka.stream.ActorMaterializer | |
import scala.io.StdIn | |
import akka.stream.scaladsl.Flow | |
import akka.http.scaladsl.model.ws.{ Message, TextMessage } | |
object WebServer extends App { | |
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.actor.typed.{ ActorSystem, SpawnProtocol } | |
object ChatSessionMap { | |
// mutable data structure holding all the chat sessions. Definition to follow | |
private var sessions: Map[String, ChatSession] = Map.empty[String, ChatSession] | |
// only function of this class is to keep track of chat sessions | |
def findOrCreate(userId: String)(implicit system: ActorSystem[SpawnProtocol.Command]): ChatSession = sessions.getOrElse(userId, create(userId)) | |
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.actor.typed.{ Behavior, SpawnProtocol, ActorRef } | |
import akka.actor.typed.scaladsl.Behaviors | |
object SessionActor { | |
// protocol - see gist below | |
import CoreChatEvents._ | |
import WebSocketsEvents._ | |
def receive(websocket: Option[ActorRef[WebSocketsEvent]]): Behavior[CoreChatEvent] = Behaviors.receiveMessage { |
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.actor.typed.ActorRef | |
object CoreChatEvents { | |
import WebSocketsEvents._ | |
sealed trait CoreChatEvent | |
final case class UserMessage(message: String, phoneNumber: String) extends CoreChatEvent | |
final case class SMSMessage(sender: String, message: String) extends CoreChatEvent | |
final case class Connected(websocket: ActorRef[WebSocketsEvent]) extends CoreChatEvent | |
final case object Disconnected extends CoreChatEvent |
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 scala.concurrent.{ Future, ExecutionContext } | |
import akka.actor.typed.{ ActorRef, ActorSystem, SpawnProtocol, Props, DispatcherSelector } | |
import akka.actor.typed.SpawnProtocol.Spawn | |
import akka.http.scaladsl.model.ws.{ TextMessage, Message } | |
import akka.stream.{ FlowShape, OverflowStrategy } | |
import akka.stream.scaladsl._ | |
import akka.stream.typed.scaladsl.{ ActorSink, ActorSource } | |
import akka.util.Timeout |
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
implicit val spawnSystem = ActorSystem(SpawnProtocol(), "spawn") | |
def messageRoute = | |
// pattern matching on the URL | |
pathPrefix("message" / Segment) { trainerId => | |
// await on the webflow materialization pending session actor creation by the spawnSystem | |
Await.ready(ChatSessionMap.findOrCreate(trainerId).webflow(), Duration.Inf).value.get match { | |
case Success(value) => handleWebSocketMessages(value) | |
case Failure(exception) => | |
println(exception.getMessage()) |
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
// defining the parent entity | |
object Parent { | |
sealed trait Command | |
sealed trait Event | |
final case class State(...) | |
val empty: State = ??? | |
def apply(parentId: String) = EventSourcedBehavior( | |
persistenceId = PersistenceId(parentId), | |
emptyState = empty, |
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
PATH := $(PWD)/node_modules/.bin:$(PATH) | |
SHELL := /bin/bash | |
# Assumes the following structure: | |
# source-dir | |
# - public | |
# - styles.css (main CSS file with Tailwind directives) | |
# - index.html (entry index.html with css and javascript links | |
# - index.js (main JS file that inits Elm app and implements ports | |
# - src/App.elm (elm entry file) |
OlderNewer