Skip to content

Instantly share code, notes, and snippets.

@eungju
eungju / DeploymentEnvironment.kt
Last active April 1, 2024 14:01
Kotlin Embedded Config
open class DeploymentEnvironment<T : Any>(
val base: T,
vararg val profiles: Pair<String, (T) -> T>
) {
companion object {
fun <T : Any> config(clazz: Class<T>, name: String, profiles: Iterable<String> = emptyList()): T {
return (Class.forName(clazz.`package`.name + "." + name).kotlin.objectInstance as DeploymentEnvironment<T>)
.config(profiles)
}
@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 / 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 / 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 / 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 / otp.rb
Last active December 21, 2022 11:16
OTP
#!/usr/bin/env ruby
require 'base32'
require 'openssl'
require 'uri'
TOTP_INTERVAL = 30
def get_pasword(secret_key, t)
now = t / TOTP_INTERVAL
@eungju
eungju / otp.hs
Last active December 21, 2022 11:09
Google Authenticator in Haskell
#!/usr/bin/env runghc
import qualified Codec.Binary.Base32 as Base32
import Codec.Utils (i2osp, fromTwosComp)
import qualified Control.Arrow as Arrow
import Data.Bits
import Data.Char
import Data.Functor
import Data.HMAC
import Data.List.Split
@eungju
eungju / README.md
Last active July 5, 2022 21:18
Kotlin let run apply also

let

inline fun <T, R> T.let(block: (T) -> R): R = block(this)

run

inline fun <T, R> T.run(block: T.() -> R): R = block()

apply

@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 / 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()) }
}