Skip to content

Instantly share code, notes, and snippets.

View hikaMaeng's full-sized avatar

hika, maeng hikaMaeng

View GitHub Profile
package com.example.demo
import org.springframework.boot.autoconfigure.SpringBootApplication
@SpringBootApplication
class DemoApplication
fun main(args: Array<String>) {
val p1 = Person("초기이름1", "초기성1")
val p2 = Person("초기이름2", "초기성2")
p1.firstName = "기완"
package kore.ocr
import kore.vo.VO
import kore.vo.field.value.float
import kore.vo.field.value.int
import kore.vo.field.value.string
import kore.vo.field.voList
import net.sourceforge.tess4j.Tesseract
import java.awt.image.BufferedImage
import java.io.File
package kore.pdf
import com.itextpdf.html2pdf.ConverterProperties
import com.itextpdf.html2pdf.HtmlConverter
import com.itextpdf.io.font.FontProgramFactory
import com.itextpdf.io.source.ByteArrayOutputStream
import com.itextpdf.kernel.geom.PageSize
import com.itextpdf.kernel.pdf.PdfDocument
import com.itextpdf.kernel.pdf.PdfWriter
import com.itextpdf.layout.font.FontProvider
package com.example.demo.service;
import java.util.HashMap;
import java.util.Map;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.chat.prompt.PromptTemplate;
import org.springframework.ai.converter.BeanOutputConverter;
import org.springframework.ai.openai.OpenAiChatOptions;
fun jsonParser1(){
val json = """{"a":1, "b":"abc", "c":true, "d":null}"""
val map:HashMap<String, Any?> = hashMapOf()
map["a"] = 1
map["b"] = "abc"
map["c"] = true
map["d"] = null

Chapter 4

Spring에서 코루틴으로 http2 전이중 통신 구현


4-1 배경

http2(이하 h2)는 기존과 달리 헤더 압축과 프레임 단위 전송을 도입해 성능을 크게 개선했다. 모든 데이터는 하나의 TCP 연결 위에서 다중 스트림으로 교차 처리되며, 서버는 요청을 기다리지 않고 준비된 응답을 먼저 보낼 수 있다. 이로써 클라이언트와 서버는 서로 독립적으로 데이터를 주고받는 전이중 통신을 실현한다. 스프링프레임웍은 MVC로는 이러한 전이중(duplex)의 구조를 활용할 수 없고 웹플럭스기반의 아키텍쳐에서만 사용할 수 있다. h2의 대표적인 기능 중엔 널리 알려진 SSE가 있다. 이는 http1.1의 롱폴링(long polling)과는 다르다. 확보된 TCP세션안에서 필요할 때 프레임을 전송하는 기술이다. 하지만 SSE조차 그저 응답시의 프레임을 사용할 뿐이다. 진정한 전이중은 요청과 응답을 별도로 처리할 수 있어야한다.

fun main() {
// val a = "url"
// val b = optional({ a.length > 2 } ){
// println("a > 2")
//
// }
// b()
// val iter = iterator(0, {
// if(it < 10) it + 2 else null
// }){
@file:Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE")
package kore.chromaDB
import kore.coroutine.awaitAll
import kore.net.RestAPI
import kore.net.getWebClient
import kore.savable.JSON
import kore.util.arrayListFillOf
import kore.util.uuid
package week3
fun checkMK(v:String):Pair<Int, Int>{
val split = v.split(" ")
if(split.size != 2 || split[0].isEmpty() || split[1].isEmpty()) throw Exception("invalid mk-$v-")
val m = split[0].toIntOrNull() ?: throw IllegalArgumentException("invalid int m")
if(m !in 1.. 1000) throw Throwable("out of range 1..1000 m: $m")
val k = split[1].toIntOrNull() ?: throw IllegalArgumentException("invalid int k")
return m to k
}
package week3
import kotlin.math.abs
/*
In the country of Voronoi, there are villages, located at distinct points on a straight road. Each of these villages will be represented by an integer position along this road.
Each village defines its neighbourhood as all points along the road which are closer to it than to any other village. A point which is equally close to two distinct villages
and
is in the neighbourhood of
and also in the neighbourhood of
.