프로세스 이름에 특정 문자열을 가진 프로세스

pkill -f 'PATTERN' 참고 자료 https://unix.stackexchange.com/questions/316065/how-to-kill-all-process-with-given-name

2024-09-15 · 1 min · 6 words

페이징을 어떻게 표현하면 좋을까

두 가지 방법이 나왔었다. URI 경로: /rooms/pages/1 URI 쿼리: /rooms?page=1 페이지를 리소스로 취급하면 리소스간의 고유한 계층을 유지하기 힘들다는 단점이 있다. 예를들어 1번방으로 요청하려면 rooms/1 이라고 표현하고 싶은데 pages라는 리소스 때문에 불가능해진다. 따라서 페이지는 rooms라는 자원을 필터링하기 위한 하나의 표현이다. 따라서 URI 쿼리 방식을 선택했다. 참고 자료 https://www.baeldung.com/rest-api-pagination-in-spring

2024-09-15 · 1 min · 47 words

파일이름으로 디렉토리인지 확인

import os os.path.isdir(full_filename) 참고 자료 https://wikidocs.net/39

2024-09-15 · 1 min · 6 words

파일의 끝 부분에 개행을 넣어야 되는 이유

UNIX OS들의 호환성을 높여주기 위한 인터페이스 규격인 POSIX에 파일의 끝부분에 개행을 추가하라는 내용이 담겨있다. 참고 자료 https://blog.coderifleman.com/2015/04/04/text-files-end-with-a-newline/ https://velog.io/@doondoony/posix-eol https://minz.dev/19

2024-09-15 · 1 min · 19 words

파일을 통해서 ContentType 찾아오는 법

Java 표준 중에 Files.probeContentType() 메소드를 사용하면 쉽게 확인할 수 있다. @Test public void whenUsingJava7_thenSuccess() { Path path = new File("product.png").toPath(); String mimeType = Files.probeContentType(path); assertEquals(mimeType, "image/png"); } https://www.baeldung.com/java-file-mime-type 파일 이름만으로 유추하는 방법도 있다. String mimeType = URLConnection.guessContentTypeFromName(file.getName()); https://stackoverflow.com/questions/9670040/what-is-the-best-approach-to-identify-a-specific-file-type-in-java

2024-09-15 · 1 min · 38 words

파일 전체 읽기

@Test public void whenReadSmallFileJava7_thenCorrect() throws IOException { String expected_value = "Hello, world!"; Path path = Paths.get("src/test/resources/fileTest.txt"); String read = Files.readAllLines(path).get(0); assertEquals(expected_value, read); } Files를 이용하면 쉽게 파일 전체를 읽을 수 있다. https://www.baeldung.com/reading-file-in-java

2024-09-15 · 1 min · 32 words

파일 이름에서 확장자 분리

splitext 함수를 호출하고 마지막 요소가 확장자가 된다. import os ext = os.path.splitext(full_filename)[-1] 참고 자료 https://wikidocs.net/39

2024-09-15 · 1 min · 15 words

파라미터로 넘어오는 값 확인하기

MyList myList = mock(MyList.class); ArgumentCaptor<String> valueCapture = ArgumentCaptor.forClass(String.class); doNothing().when(myList).add(any(Integer.class), valueCapture.capture()); myList.add(0, "captured"); assertEquals("captured", valueCapture.getValue()); https://www.baeldung.com/mockito-void-methods

2024-09-15 · 1 min · 15 words

파드에 환경 변수로 데이터 넘겨주기

목표 디플로이먼트를 이용해서 파드를 생성할 때, 파드에서 필요한 데이터를 환경 변수로 설정되도록 하여 넘겨주고자 한다. 파드에 넘겨줄 데이터를 클러스터에서 어떻게 관리할지도 고민해본다. ConfigMap 클러스터 내에 기밀이 아닌 데이터를 저장하는 데 사용하는 API 오브젝트다. 파드는 ConfigMap을 환경 변수, 파라미터 볼류의 구성 파일로 사용할 수 있다. 아래와 같이 명령어로 바로 ConfigMap을 만들 수도 있고, yaml 파일을 이요해서 만들 수도 있다. kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm apiVersion: v1 kind: ConfigMap metadata: creationTimestamp: 2022-02-18T19:14:38Z name: special-config namespace: default resourceVersion: "651" uid: dadce046-d673-11e5-8cd0-68f728db1985 data: special....

2024-09-15 · 2 min · 299 words

특정 필드가 없는 도큐먼트 조회 쿼리

목표 특정 필드가 없는 도큐먼트 조회 쿼리 작성법을 이해한다. exists exists 쿼리를 통해서 필드를 존재하는 도큐먼트를 필터링할 수 있다. GET /_search { "query": { "exists": { "field": "user" } } } 아래 예시와 같이 must_not을 통해 필드가 없는 도큐먼트도 조회가 가능하다. GET /_search { "query": { "bool": { "must_not": { "exists": { "field": "your_field" } } } } } 참고 자료 https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html https://stackoverflow.com/questions/29357148/how-to-filter-out-fields-that-do-not-exist-in-elastic-search

2024-09-15 · 1 min · 63 words

특정 포트를 사용하고 있는 프로세스 찾기

lsof -i :포트번호 참고 자료 https://sas-study.tistory.com/281

2024-09-15 · 1 min · 6 words

특정 패키지에 있는 클래스들의 빈 생성자 전부 호출하기

1. 특정 패키지에 있는 클래스 가져오기 이전에 학습했던 System Class Loader를 이용하면 특정 패키지에 있는 모든 클래스를 가지고 올 수 있다. private Set<Class<?>> findAllClassesUsingClassLoader(String packageName) { final InputStream stream = ClassLoader.getSystemClassLoader() .getResourceAsStream(packageName.replaceAll("[.]", "/")); final BufferedReader reader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(stream))); return reader.lines() .filter(line -> line.endsWith(".class")) .map(line -> getClass(line, packageName)) .collect(Collectors.toSet()); } private Class<?> getClass(String className, String packageName) { final String classPath = packageName + "." + className.substring(0, className.lastIndexOf('.')); try { return Class....

2024-09-15 · 1 min · 201 words

특정 파드 로그 확인하기

목표 특정 파드에 발생하는 로그를 실시간으로 확인한다. 특정 파드가 재시작 되었을 때 이전 인스턴스의 로그를 확인한다. 방법 기본적으로 kubectl logs <파드 id> 로 파드의 로그를 확인할 수 있다. -f 옵션은 follow의 약자로 로그가 스트리밍 되는 옵션이다. kubectl logs -f <파드 id> 에러 등으로 인해 파드가 재시작되었다면, 재시작 원인을 분석하기 위해 이전 인스턴스의 로그를 확인할 필요도 있다. -p: previous의 약자 kubectl logs -p <파드 id> 참고 자료 https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#logs https://stackoverflow.com/questions/39454962/kubectl-logs-continuously https://www.digitalocean.com/community/questions/how-to-check-the-logs-of-running-and-crashed-pods-in-kubernetes

2024-09-15 · 1 min · 69 words

특정 컬럼에 null이 아닌 row의 개수 구하기

sum(case when [session.id](http://session.id/) is null then 0 else 1 end) case 키워드를 이용하면 된다. 참고 자료 https://www.sqlshack.com/working-with-sql-null-values/

2024-09-15 · 1 min · 17 words

특정 주기마다 실행되는 메서드

Spring task라는 내장된 기능 통해 특정 메서드를 주기적으로 실행하는 것이 가능하다. 스케쥴링 지원 활성화 Configuration에 @EnableScheduling 어노테이션을 추가하면 활성화된다. @Configuration @EnableScheduling public class SpringConfig { ... } fixed 방식 fixed 방식에는 2가지가 있다. fixedDelay: 작업이 종료된 시간부터 지정된(ms단위) 시간 뒤에 재실행. fixedRate: 작업이 시작된 시간부터 지정된(ms단위) 시간 뒤에 재실행. @Scheduled(fixedDelay = 1000) public void scheduleFixedDelayTask() { System.out.println( "Fixed delay task - " + System.currentTimeMillis() / 1000); } @Scheduled(fixedRate = 1000) public void scheduleFixedRateTask() { System....

2024-09-15 · 1 min · 181 words

특정 문자열로 시작하는 값 조회

방법 CONCAT을 이용해야 된다. SELECT * FROM TABLE_NAME WHERE COLUMN_NAME LIKE CONCAT(‘%’, #{searchKeyword}) 참고 자료 https://dongram.tistory.com/12

2024-09-15 · 1 min · 16 words

특정 메소드가 호출된 횟수 검증

Mockito.verify(utilClass, Mockito.times(1)).method(); https://stackoverflow.com/questions/57775074/mockito-veify-is-giving-wrong-invocation-count

2024-09-15 · 1 min · 3 words

특정 디렉토리의 하위 디렉토리 검색

os.walk() 함수를 사용하면 된다. import os for (path, dir, files) in os.walk("c:/"): for filename in files: ext = os.path.splitext(filename)[-1] if ext == '.py': print("%s/%s" % (path, filename)) 참고 자료 https://wikidocs.net/39

2024-09-15 · 1 min · 30 words

특정 디렉토리의 파일 리스트

import os os.listdir(dirname) 참고 자료 https://wikidocs.net/39

2024-09-15 · 1 min · 6 words

특정 디렉토리에 있는 전체 파일 가져오기

Files.walk 메소드는 현재 입력받은 경로로부터 파일 트리를 전부 탐색해서 stream 으로 반환한다. Files.walk(Paths.get("folder")) .filter(Files::isRegularFile) .forEach(System.out::println); folder\file1.txt folder\file2.txt folder\subfolder\file3.txt folder\subfolder\file4.txt 현재 디렉토리에 있는 파일만 가져올 경우는 list() 메소드를 사용하면 된다. Files.list(Paths.get("folder")) .filter(Files::isRegularFile) .forEach(System.out::println); folder\file1.txt folder\file2.txt https://stackoverflow.com/questions/1844688/how-to-read-all-files-in-a-folder-from-java https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html

2024-09-15 · 1 min · 36 words