Skip to content

Instantly share code, notes, and snippets.

@hanishi
hanishi / index.tsx
Last active March 7, 2024 03:36
AutocompleteServer for ChatGPT
type CacheEntry<T> = {
value: T,
timeout: ReturnType<typeof setTimeout>,
}
class ExpiringCache<T> {
private readonly cache: Record<string, CacheEntry<T>>;
private readonly expirationTime: number;
constructor(expirationTime: number = 5000) {
package actors
import actors.CpcActuator.Actor.{ FetchMeasurementKey, TimeoutKey, Work }
import akka.actor.typed.scaladsl.{ ActorContext, Behaviors, StashBuffer, TimerScheduler }
import akka.actor.typed.{ ActorRef, Behavior, SupervisorStrategy }
import akka.util.Timeout
import com.google.inject.Provides
import play.api.Configuration
import play.api.libs.concurrent.ActorModule
import usecase.SamplePublisherService
@hanishi
hanishi / Aggregator.scala
Last active November 6, 2022 13:22
Sample parent-child actors with aggregator for collecting the status of child actors.
package actors
import akka.actor.typed.scaladsl.Behaviors
import akka.actor.typed.{ActorRef, Behavior}
import scala.collection.immutable
import scala.concurrent.duration.FiniteDuration
import scala.reflect.ClassTag
//see https://github.com/akka/akka/blob/v2.7.0/akka-actor-typed-tests/src/test/scala/docs/akka/typed/Aggregator.scala
@hanishi
hanishi / Child.scala
Last active November 20, 2023 09:18
Parent Child using Akka Typed
package example
import akka.Done
import akka.actor.typed.scaladsl.{
ActorContext,
Behaviors,
StashBuffer,
TimerScheduler
}
import akka.actor.typed.{ActorRef, Behavior, SupervisorStrategy}
import typings.express.mod as express
import typings.express.mod.{RequestHandler, request_=}
import typings.expressServeStaticCore.mod.*
import typings.node.bufferMod.global.Buffer
import typings.node.processMod as process
import wvlet.airframe.log
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.DurationInt
import scala.concurrent.{ExecutionContext, Future}
package example
import akka.actor.typed.ActorSystem
import akka.actor.typed.scaladsl.AskPattern.{Askable, schedulerFromActorSystem}
import akka.util.Timeout
import com.typesafe.config.ConfigFactory
import example.asyncHandler.{Req, Res}
import org.scalablytyped.runtime.StringDictionary
import typings.express.mod as express
import typings.node.bufferMod.global.Buffer
package example
import akka.Done
import akka.actor.typed.scaladsl.{ActorContext, Behaviors, StashBuffer, TimerScheduler}
import akka.actor.typed.{ActorRef, Behavior, SupervisorStrategy}
import akka.pattern.StatusReply
import org.scalablytyped.runtime.StringDictionary
import typings.cheerio.cheerioMod.Cheerio
import typings.cheerio.mod.Node
import typings.devtoolsProtocol.mod.Protocol.Network.ResourceType
package example
import akka.actor.typed.scaladsl.{ActorContext, Behaviors, StashBuffer}
import akka.actor.typed.{ActorRef, Behavior, SupervisorStrategy}
import akka.pattern.StatusReply
import akka.util.Timeout
import typings.node.bufferMod.global.Buffer
import typings.puppeteer.mod.Browser
import java.util.UUID.randomUUID
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.7.1")
addSbtPlugin("org.scalablytyped.converter" % "sbt-converter" % "1.0.0-beta36")
@hanishi
hanishi / build.sbt
Last active December 3, 2021 14:54
lazy val root = (project in file("."))
.enablePlugins(ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, nodeProject)
.settings(
useYarn := true,
name := "squid-game",
scalaJSUseMainModuleInitializer := true,
libraryDependencies += ("org.akka-js" %%% "akkajsactortyped" % "2.2.6.14").cross(CrossVersion.for3Use2_13),
libraryDependencies += ("org.akka-js" %%% "akkajstypedtestkit" % "2.2.6.14" % "test").cross(CrossVersion.for3Use2_13),
libraryDependencies += ("org.akka-js" %%% "akkajsactorstreamtyped" % "2.2.6.14").cross(CrossVersion.for3Use2_13),