2020/03 3

leetcode 1379(트리), 46(permutation), 98(트리), 173(트리)

1379번. https://leetcode.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree/ 트리 순환 문제이다. 왜 굳이 original과 cloned을 따로 나눴는지 모르겠다. pre order던 post order던 순회하면서 해당 val이 있으면 return하도록 하면 문제는 풀린다. 아래는 일반적인 dfs식 트리순회. class Solution(object): def getTargetCopy(self, original, cloned, target): stack = [cloned] while stack: pop = stack.pop() if pop.val == target.val: return pop i..

python get autoscaling group ip list

https://stackoverflow.com/questions/47558854/boto3-to-pull-all-ec2-instances-from-a-given-asg 나중에 보기 위해 코드 저장해둠. 오토 스케일링 그룹 내의 인스턴스 하나하나로 ssh로 들어가야 할 경우가 많은데 오토 스케일링 그룹 내의 인스턴스가 좀 많으면 aws콘솔에서는 하나하나 확인하기가 너무 짜증난다. 다시 들어가서 로딩되는데 시간도 오래걸리고.. 그래서 ip리스트를 받아오는 코드가 있으면 매우 쉽게 해당 ip로 들어갈수 있는 ssh프로그램을 짤 수 있다. # -*- coding: utf-8 -*- import boto3 class AwsManager: def __init__(self): self.access_key = aws ..

data engineering 2020.03.26

remove docker image over 2 month

로컬에서 테스트로 도커 빌드를 자주 해보는데 이미지가 계속 쌓인다. 이미지를 계속해서 만들다보면 도커의 이미지를 저장하는곳의 공간이 풀나서 정말 몇개월에 한번씩 이미지를 더이상 생성할수 없다고 나오는데 2달이 지난 이미지는 필요없다고 판단해 지우는 스크립트를 하나 만들었다. 여기에 저장해놓고 가져다가 쓰려고 간단하게 만들어둠. python3 import subprocess import re def get_docker_image_list(name): docker_image_list, _ = subprocess.Popen(['docker', 'image', 'ls'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() docker_image_lis..