Skip to content

Instantly share code, notes, and snippets.

View stella6767's full-sized avatar
🎯
Focusing

Kang Min Kyu stella6767

🎯
Focusing
View GitHub Profile
@stella6767
stella6767 / curryFunc.kt
Created August 18, 2022 05:15
코틀린 고차함수 테스트
object CustomAopObject {
val log = KotlinLogging.logger { }
/**
* 커리함수테스트
*/
fun <T> manageTransaction(method: () -> T): T? {
try {
@stella6767
stella6767 / AsyncConfig.kt
Created August 18, 2022 05:11
스프링부트 비동기 설정
@EnableScheduling
@EnableAsync
@Configuration
class AsyncConfig(
) : AsyncConfigurerSupport() {
/**
* 최초 coreSize개의 스레드에서 처리하다가 처리 속도가 밀릴 경우
* queueCapacity 사이즈 queue에서 대기하고 그보다 많은 요청이 들어올 경우
@stella6767
stella6767 / MemoryTokenRepositoryImpl.kt
Created August 18, 2022 05:09
expiringmap을 활용한 인메모리 저장소
@Repository
class MemoryTokenRepositoryImpl : TokenRepository {
/**
* https://hippolab.tistory.com/44
* concurrent 지원
* refresh token 저장용
*/
private val log = KotlinLogging.logger { }
@stella6767
stella6767 / numberOfThreads.kt
Last active August 18, 2022 05:10
동시성 테스트
@Test
fun tokenRepositoyTest(){
val tokenRepository:TokenRepository = MemoryTokenRepositoryImpl()
val numberOfThreads = 1000
val service = Executors.newFixedThreadPool(10)
val latch = CountDownLatch(numberOfThreads)
for ( index in 1..numberOfThreads){
service.submit {
@stella6767
stella6767 / staticFactoryMethodWithKotlin.kt
Created August 18, 2022 02:40
staticFactoryMethodWithKotlin
interface QuerryRunner {
fun getInstance(): QueryRunnerFactory
}
class QueryRunnerFactory(
) : QuerryRunner {
companion object Factory {
var queryRunner = QueryRunnerFactory()
@stella6767
stella6767 / Inject into static field.kt
Created August 18, 2022 02:38
Inject into static field Kotlin/Spring Boot
@Component
class GlobalValue {
companion object {
@JvmField
lateinit var DATABASE: String
}
@Value("\${mongodb.db}")
fun setDatabase(db: String) {
DATABASE = db;
@stella6767
stella6767 / convertPojoToUrlEncodedFormData.kt
Last active August 11, 2022 01:25
convertPojoToUrlEncodedFormData
fun convertPojoToUrlEncodedFormData(obj: Any?): String {
/**
* 간단한 함수 input + output 테스트를 위하므로, ObjectMapper를 의존성 주입시키지 않겠다.(스프링과는 독립적인)
* util function들은 최대한 의존성 없이
*
*/
val map: Map<*, *>? = ObjectMapper().convertValue(obj, Map::class.java)
@stella6767
stella6767 / ResponseBodyAdvice.kt
Created August 9, 2022 07:58
공통 response body modify
@org.springframework.web.bind.annotation.RestControllerAdvice
class RestControllerAdvice<T>(
) : ResponseBodyAdvice<T>{
private val log = KotlinLogging.logger { }
override fun supports(returnType: MethodParameter, converterType: Class<out HttpMessageConverter<*>>): Boolean {
//log.info { "returnType: $returnType" }
return true
@stella6767
stella6767 / pathParsingTest.kt
Created August 9, 2022 07:50
pathParsingTest
@Test
fun pathParsingTest() {
val path = "/v1/members"
log.info {
path.split(delimiters = arrayOf("/"," ")).filter { it.isNotEmpty() }.forEach {
println(" $it ")
}
}
@stella6767
stella6767 / kcc.js
Created August 9, 2022 06:33
javascript 리터럴 오브젝트 활용
let rds = {
monUiCtl: [],
isRun: false,
ctlUIStart: function (idx, ch) {
console.log("ctlUIStart????", idx, ch);
this.monUiCtl[idx].value.changeLayout(
1,