Skip to content

Instantly share code, notes, and snippets.

@ruseel
ruseel / a.clj
Created April 18, 2024 23:09
What file is raising MalformedInputException on slurp?
;; What file is raising MalformedInputException on slurp?
(use 'clojure.java.io)
(import 'java.nio.file.Files)
(import 'java.nio.file.Paths)
(import 'java.nio.charset.MalformedInputException)
(def directory? (memfn isDirectory))
(def name (memfn getName))
public class NamedParamStatement {
public NamedParamStatement(Connection conn, String statementWithNames) throws SQLException {
Pattern findParametersPattern = Pattern.compile("(?<!')(:[\\w]*)(?!')");
Matcher matcher = findParametersPattern.matcher(statementWithNames);
while (matcher.find()) {
fields.add(matcher.group().substring(1));
}
prepStmt = conn.prepareStatement(statementWithNames.replaceAll(findParametersPattern.pattern(), "?"));
}
@ruseel
ruseel / s3-dist-cp.md
Last active October 13, 2023 03:20
Amazon EMR 에서 s3-dist-cp 사용하기
  • emr에서 s3-disp-cp를 어떻게 실행하나?
  • 각 option의 의미는 뭔가?
  • 어떻게 escape 시켜야 하나?

amazon emr 4.3.0 distribution 에서는 master 서버에 s3-dist-cp라는 명령을 바로 실행할 수 있다.[1][2]

src dest 옵션만 주면 기본 형태다. cp -R 명령과 동일하게 src 전체를 dest로 복사한다.

   s3-dist-cp --src s3://bucket-src --dest s3://bucket-dest 
@ruseel
ruseel / keycloak-rest-api-sample.clj
Last active August 27, 2023 18:17
Keycloak Admin REST API Sample
;; this worked for me
;;
(defn access-token []
(->
(client/post
(str base-url "/auth/realms/" realm "/protocol/openid-connect/token")
{:accept :json
:form-params {"client_id" "admin-cli"
"username" some-username
@ruseel
ruseel / README.md
Last active January 16, 2023 06:31
lacinia - resolve-promise - go,future,promesa/future,promesa/thread - {invoke,invoke-async}

lacinia 의 resolver 구성에 대해서 좀 더 알아야 (async 혹은 ThreadPoolExecutor) 의 동작을 이해할 수 있을 것 같습니다.

lacinia 에서 resolver 를 구현할 때 value 를 바로 리턴하도록 할 수도 있지만 ResolveResultPromise 를 리턴하게 할 수도 있습니다. [1] lacinia 에서 이것을 "Asynchronous Field Resolvers" 라고 부릅니다.

resolver 에서 ResolveResultPromise 를 리턴하게 만들 때는 아래와 같은 pattern 을 따릅니다.

(defn resolve-xyz
@ruseel
ruseel / emoji-subs.clj
Created November 18, 2022 10:29
substring java string with emoji
(import 'java.text.BreakIterator)
(defn break-index-seq [s]
(let [iter (doto (BreakIterator/getCharacterInstance)
(.setText s))
c (.first iter)
-seq (fn f [c iter]
(lazy-seq (when (not= c BreakIterator/DONE)
(cons c (f (.next iter) iter)))))]
(-seq c iter)))
@ruseel
ruseel / README.md
Created March 4, 2022 08:28
mitmproxy for gRPC server-streaming response

When you request gRPC through mitmproxy and the server responses with streaming client is not receiving that response.

Because mitmproxy tries to read entire response for manipulating opportunity.

So in that case, we can use '--set stream_large_bodies=1' option.

https://docs.mitmproxy.org/stable/overview-features/#streaming

@ruseel
ruseel / aws-docker-high-tracffic-kernel.md
Last active January 7, 2022 05:42
AWS에서 docker를 쓸 때 high traffic server라면 이렇게

AWS에서 docker를 쓸 때 high traffic server라면 이렇게 하는 것이 좋겠다. amazon linux를 쓴다고 하자.

ulimit

ulimit를 올려주어야 한다. /etc/security/limit.conf 에서 고쳐주어도 docker에는 적용되지 않는다. limit.conf는 PAM을 통해서 로그인했을 때만 먹는 설정이라 그렇다. docker로 띄운 process의 pid를 찾고 cat /proc/<pid>/limits를 실행해서 보면 적용되었는지 아닌지 확실하게 알 수 있다. kernel에서 직접 그 프로세스에 어떤 ulimit이 적용되었는지 확인하는 방법이다.

그래서 /etc/sysconfig/docker 파일을 만들고 아래를 추가한다.

@ruseel
ruseel / BUILD.bazel
Last active December 21, 2021 09:24
varticle/bazel-distribution deploy_maven example
load('@vaticle_bazel_distribution//maven:rules.bzl', "assemble_maven", "deploy_maven")
java_library(
name = "some_lib",
resources = glob(["src/test/resources/**/*"]),
tags = ["maven_coordinates=group_id:artifact:{pom_version}"],
)
assemble_maven(
name = "assemble",
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
ko:
errors:
messages:
expired: "가(이) 만료되었습니다. 새로 요청해 주십시오"
not_found: "를(을) 찾을 수 없습니다"
already_confirmed: "이미 확인되었습니다, 다시 로그인 해 주십시오"
not_locked: "가(이) 잠기지 않았습니다"
not_saved: