Skip to content

Instantly share code, notes, and snippets.

View jsrimr's full-sized avatar

Jungsub Lim jsrimr

  • Galux Inc
  • Seoul, Dongjak-gu
View GitHub Profile
@jsrimr
jsrimr / 중복제거.sql
Created September 28, 2020 02:56
db 중복 row 제거 쿼리
DELETE
FROM log_by_hour
WHERE id IN
(
SELECT id FROM (SELECT max(id) FROM log_by_hour where time BETWEEN FROM_UNIXTIME(1598927371) AND FROM_UNIXTIME(1598956231) GROUP BY instance_id, cmd_id, time, min, max, avg HAVING count(*) > 1) temp_table
)
and time BETWEEN FROM_UNIXTIME(1598927371) AND FROM_UNIXTIME(1598956231)
;
DELETE
@jsrimr
jsrimr / 2types_binSearch.py
Created September 10, 2020 14:33
binary serach 2가지 유형. Exact match and close match. close match 가 필요한 경우 : https://programmers.co.kr/learn/courses/30/lessons/64062
def find_closest():
"""
max_consecutive_cnt == k 인 경우가 여러개 있을 수 있다. 이 중 stone 을 가장 작게 하는 경우를 찾는다.
일단, max_consecutive_cnt >= k 를 만족하긴 해야한다. 여기를 =mid 로 잡고
나머지 한쪽을 mid-1 이나 mid+1 해서 실험하는 용도로 사용한다.
left 는 항상 k에 못미달하는 구간으로(실패) 업데이트시 max_consecutive_cnt < k 일때 left = mid+1
right 는 항상 k에 도달하는 구간으로(실패) max_consecutive_cnt >= k 에서 업데이트시 right = mid
"""
@jsrimr
jsrimr / executeSqlFile.py
Created August 12, 2020 11:37
executeSqlFile by python
import pymysql
from settings import db_host, db, db_user, db_password
def executeScriptsFromFile(filename):
# Open and read the file as a single buffer
fd = open(filename, 'r')
sqlFile = fd.read()
fd.close()
# all SQL commands (split on ';')
sqlCommands = sqlFile.split(';')
@jsrimr
jsrimr / celery_run.sh
Created August 6, 2020 08:38
run python module celery with env variables and virtualenv
set -a
source ../.env.local
set +a
/Users/jungsublim/.pyenv/versions/anaconda3-5.1.0/envs/cloaweb/bin/celery -A conf.celery worker -l info -B
@jsrimr
jsrimr / custom.ini
Created July 31, 2020 05:34
외부에서 iframe 으로 grafana view 할 수 있도록 하는 설정. 모든 권한을 다 할 수 있는 것 같아 조정이 필요해보임. 설정파일 바꾸고 docker restart [grafana_container_name] 하면 됨
##################### Grafana Configuration Example #####################
#
# Everything has defaults so you only need to uncomment things you want to
# change
# possible values : production, development
;app_mode = production
# instance name, defaults to HOSTNAME environment variable value or hostname if HOSTNAME var is empty
;instance_name = ${HOSTNAME}
class Trie:
head = {}
def add(self, word):
cur = self.head
for ch in word:
if ch not in cur:
cur[ch] = {}
cur = cur[ch]
# *가 있을 경우, 그 단어가 자료구조에 저장되어 있음을 의미
# *가 없을 경우, 그 단어는 자료구조에 저장되어 있지 않음, 단지 더 긴 단어의 부분으로만 존재함
@jsrimr
jsrimr / Trie.py
Last active July 30, 2020 13:11
트라이구현
class Trie:
def __init__(self):
self.head = {}
def add(self, word):
cur = self.head
for ch in word:
if ch not in cur:
cur[ch] = {}
cur = cur[ch]
from typing import List
class Solution:
def exist(self, board: List[List[str]], word: str) -> bool:
#dfs
stack = [(0,0,0,set())]
r , c = (len(board) , len(board[0])if board else 0 )
while stack:
i, j, c , visited= stack.pop()
print(board[i][j])
if (i,j) in visited:
@jsrimr
jsrimr / simulation.sh
Created July 9, 2020 03:39
for문 순회하며 curl Post 하는 shell script
while true
do
for ((i=52;i<100;i++));
do
curl -X POST -H "Content-Type: application/json" -d @data.json 10.128.0.22:8080/logs/cloa/$i &
done
sleep 3
done
def solution(bridge_length, weight, truck_weights):
# 트럭 대수는 bridge_len 보다 작고, 트럭 무게 합은 weight 보다 작아야함
bridge = []
time, cur_weight, interval = 0, 0, 0
while truck_weights:
if bridge[0][1] < bridge_length and len(bridge) < bridge_length and cur_weight + truck_weights[0] <= weight: # 새로 태우자