Skip to content

Instantly share code, notes, and snippets.

View brianhsu's full-sized avatar

Brian Hsu brianhsu

View GitHub Profile
@Configuration
@Slf4j
public class DataSourceConfig {
@Bean
@Primary
@ConfigurationProperties(prefix = "spring.datasource.pws")
public DataSourceProperties pwdDataSourceProperties() {
return new DataSourceProperties();
}
import socket
import sys
import time
if len(sys.argv) == 3:
# Get "IP address of Server" and also the "port number" from argument 1 and argument 2
ip = sys.argv[1]
port = int(sys.argv[2])
else:
print("Run like : python3 client.py <arg1 server ip 192.168.1.102> <arg2 server port 4444 >")
@brianhsu
brianhsu / akka.scala
Created May 27, 2020 06:06
akka.scala
package com.example
import akka.actor.typed.{ActorRef, ActorSystem, Behavior, SupervisorStrategy, Terminated}
import akka.actor.typed.scaladsl.{Behaviors, PoolRouter, Routers}
import com.example.ParentActor._
import com.example.Transformer.{ConvertPlease, GracefulShutdown}
object Transformer {
sealed trait Request
{"name": "Michael", "age": 32, "gender": "male", "country": "TW"}
{"name": "David", "age": 12, "gender": "male", "country": "HK"}
{"name": "Amy", "age": 20, "gender": "female", "country": "HK"}
{"name": "Andy", "age": 40, "gender": "male", "country": "TW"}
case class StringList(xs: List[String]) {
def prepend(element: String) = StringList(element :: xs)
}
val xs = List(1, 2, 3, "aa", "bb", "cc", 4, 5.5, 7, "dd", "ee", "ff", "gg", 8, 9.2, 10)
val r = xs.foldRight(List.empty[Any]) {
case (current: String, compactedList @ ((strList: StringList) :: xs)) => strList.prepend(current) :: xs
case (current: String, compactedList @ (_ :: xs)) => new StringList(current :: Nil) :: compactedList
case (current: Int, compactedList) => current :: compactedList
import scala.util.parsing.combinator._
case class Anyline(x: String)
case class Comment(comment: String)
case class Index(mode: String)
case class Field(iden: String, dataType: String, data: Any)
case class Block(name: String, data: Any)
object MyParsers extends RegexParsers {
override val whiteSpace = """[ \t]+""".r
val useCase = new BaseUseCase[Int] {
def execute() = 100
}
val result = executor.execute(useCase) { r => r }
result shouldBe Success(100)
val useCase = new BaseUseCase[Int] {
def execute() = 100
}
var isCalled = false
var useCaseResult: Try[Int] = Failure(new NoSuchElementException)
executor.execute(useCase) { result =>
isCalled = true
useCaseResult = result
object UseCaseExecutor {
type Presenter[T] = (Try[T] => Unit)
}
abstract class UseCaseExecutor {
import UseCaseExecutor.Presenter
def execute[T](useCase: UseCase[T])(presenter: Presenter[T]): Unit = {
class UserToJSONPresenter extends CreateUserPresenter {
private var mData: User = _
def onResult(user: User) {
mData = user
}
def toJSON = ???
}
val executor = new NoLogUseCaseExecutor
val useCase = new CreateUser(....)
val newUser = executor.execute(useCase, presenter)