Skip to content

Instantly share code, notes, and snippets.

@eungju
eungju / EmbeddedConfig.kt
Last active March 28, 2024 14:22
Kotlin Embedded Config
class EmbeddedConfig<T>(private val clazz: Class<T>) {
fun load(configName: String, profileNames: Iterable<String> = emptyList()): T {
val configClass = Class.forName(clazz.`package`.name + "." + configName).kotlin
val configObject = configClass.objectInstance!!
val configProp = configClass.members.first { it.name == "config" } as KProperty1<Any, T>
val profiles = profileNames
.map { name ->
configClass.members.firstOrNull { it.name == name } as KProperty1<Any, (T) -> T>
}
.map { it.get(configObject) }
@eungju
eungju / I18n.kt
Last active March 28, 2024 14:19
Simple i18n
interface I18n {
fun localized(languageTag: String): Localized
interface Localized {
fun text(key: String, args: Map<String, Any>): String
fun text(key: String): String = text(key, emptyMap())
}
}
@eungju
eungju / Hints for Computer System Design.html
Last active April 28, 2023 01:00
Hints for Computer System Design
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<title></title>
<style type="text/css">code{white-space: pre;}</style>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
@eungju
eungju / ct_fsnotify.go
Last active March 14, 2024 07:13
Go Continuous Testing
package main
import (
"fmt"
"log"
"os"
"os/exec"
"time"
"github.com/fsnotify/fsnotify"
@eungju
eungju / BulkheadInterceptor.kt
Created September 9, 2021 05:56
OkHttp 지표 수집과 장애 격리
import io.github.resilience4j.bulkhead.Bulkhead
import okhttp3.Interceptor
import okhttp3.Response
class BulkheadInterceptor(private val bulkhead: Bulkhead) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response =
bulkhead.executeCallable { chain.proceed(chain.request()) }
}
@eungju
eungju / RestdocsDsl.kt
Last active July 2, 2022 14:06
Spring REST Docs Kotlin DSL
import org.springframework.restdocs.headers.HeaderDescriptor
import org.springframework.restdocs.headers.HeaderDocumentation
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation
import org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse
import org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint
import org.springframework.restdocs.payload.FieldDescriptor
import org.springframework.restdocs.payload.PayloadDocumentation
import org.springframework.restdocs.payload.SubsectionDescriptor
import org.springframework.restdocs.request.ParameterDescriptor
import org.springframework.restdocs.request.RequestDocumentation
@eungju
eungju / FixZipkinV2Reporter.kt
Last active June 13, 2021 04:46
jaeger-zipkin이 객체의 private 필드에 접근하지 않게 한다.
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import io.jaegertracing.zipkin.internal.V2SpanConverter
import java.lang.reflect.Field
import java.lang.reflect.Modifier
import java.lang.invoke.MethodHandles
import java.lang.invoke.VarHandle
class FixZipkinV2Reporter(gson: Gson = PRIVACY_RESPECTING_GSON) {
init {
@eungju
eungju / BulkheadClientInterceptor.kt
Last active February 18, 2024 02:01
resilience4j-grpc
import io.github.resilience4j.bulkhead.Bulkhead
import io.github.resilience4j.bulkhead.utils.BulkheadUtils
import io.grpc.CallOptions
import io.grpc.Channel
import io.grpc.ClientCall
import io.grpc.ClientInterceptor
import io.grpc.ClientInterceptors
import io.grpc.ForwardingClientCallListener
import io.grpc.Metadata
import io.grpc.MethodDescriptor
@eungju
eungju / TRawHttpSocket.java
Last active May 11, 2018 00:58
RawHTTP libthrift TTransport
import com.athaydes.rawhttp.core.EagerBodyReader;
import com.athaydes.rawhttp.core.EagerHttpResponse;
import com.athaydes.rawhttp.core.MethodLine;
import com.athaydes.rawhttp.core.RawHttp;
import com.athaydes.rawhttp.core.RawHttpHeaders;
import com.athaydes.rawhttp.core.RawHttpRequest;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@eungju
eungju / CircuitBreakerMetrics.kt
Last active April 12, 2018 13:59
Timeout CircuitBreaker
interface CircuitBreakerMetrics {
fun executionCompleted(name: String, latency: Double) = Unit
}