Skip to content

Instantly share code, notes, and snippets.

View milkcoke's full-sized avatar
:bowtie:
Busy boy

milkcoke milkcoke

:bowtie:
Busy boy
View GitHub Profile
@milkcoke
milkcoke / Table-Of-Contents.md
Created February 11, 2024 05:23
Obsidian ToC Template

[!SUMMARY]- Table of Contents <%*

    const headers = await tp.file.content         .split('\n') // split file into lines         .filter(t => t.match(/^[#]+\s+/gi)) // only get headers         .map(h => {             const headerLevel = h.split(' ')[0].match(/#/g).length;              // get header text without special characters like '[' and ']'

@milkcoke
milkcoke / prometheus.yaml
Last active November 1, 2023 23:18
Prometheus config example
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
# external_labels:
# monitor: 'codelab-monitor'
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
@milkcoke
milkcoke / YamlConfig.kt
Last active October 29, 2023 10:37
YamlConfig configuration
@Configuration // 클래스를 수동 빈 등록
//'application.yaml' 설정 파일로부터 prefix 통해 읽어들인다.
// property setter 방식으로 주입된다는 것이 단점이다.
@ConfigurationProperties(prefix = "")
class YamlConfig {
lateinit var name: String
lateinit var environment: String
var enabled: Boolean = false
}
@milkcoke
milkcoke / SpringBootUnitTest.kt
Created October 29, 2023 10:19
Active Profiles example
@SpringBootTest
// ActiveProfiles 어노테이션은 application.yaml 의 spring.profiles.active 값보다 우선한다.
@ActiveProfiles("test")
abstract class SpringBootUnitTest {
}
spring:
config:
activate:
on-profile: prod
name: prod-yaml
environment: prod
enabled: true
spring:
config:
activate:
on-profile: local
name: local-yaml
environment: local
enabled: false
@milkcoke
milkcoke / application.yaml
Created October 29, 2023 09:11
Application yaml multi-profiles
spring:
profiles:
# local profile 활성화
active: local
---
spring:
config:
activate:
# local profile 지정
on-profile: local
@milkcoke
milkcoke / UserConsumerMain.kt
Created October 13, 2023 15:10
User Consumer Main
class UserConsumerMain {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val config = mapOf(
ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG to UserKafkaConfig.BOOTSTRAP_SERVER,
ConsumerConfig.GROUP_ID_CONFIG to UserKafkaConfig.GROUP_ID,
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG to "earliest",
ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG to ByteArrayDeserializer::class.java,
ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG to UserDeserializer::class.java,
@milkcoke
milkcoke / UserProducerMain.kt
Created October 13, 2023 15:09
User producer main
class UserProducerMain {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val config = mapOf(
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG to UserKafkaConfig.BOOTSTRAP_SERVER,
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG to ByteArraySerializer::class.java,
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG to UserSerializer::class.java,
SaslConfigs.SASL_MECHANISM to "PLAIN"
)
@milkcoke
milkcoke / UserDeserializer.kt
Created October 13, 2023 15:04
User deserializer supporting avro class
class UserDeserializer: Deserializer<User> {
private val logger = LoggerFactory.getLogger(UserDeserializer::class.java)
override fun deserialize(topic: String?, data: ByteArray?): User? {
val datumReader = SpecificDatumReader<User>(User::class.java)
try {
val decoder = DecoderFactory
.get()
// FIXME: Expected record-start. Got START_ARRAY