Skip to content

Instantly share code, notes, and snippets.

@yjcrocks
yjcrocks / print_box.py
Created September 25, 2018 14:02
Draw box around the text. Great for debugging.
def print_box(text, line_width=2, s="#"):
text = [t.strip() for t in text.strip().split("\n")]
max_len = max(len(t) for t in text)
text = [t.ljust(max_len) for t in text]
cols = max_len + (line_width + 2 * line_width) * 2
wrap = lambda out, s: s + out + s[::-1]
gutter = s * 2 * line_width + " " * line_width
blank_line = wrap(" " * max_len, gutter) + "\n"
# generate boxed text
out = "\n".join(wrap(t, gutter) for t in text)
@yjcrocks
yjcrocks / docker
Last active September 17, 2024 09:19
다음 카카오 미러 사용하기 | Using daum kakao mirror for Ubuntu / Docker / PyPI
RUN sed -i 's/archive.ubuntu.com/mirror.kakao.com/g' /etc/apt/sources.list \
&& apt-get update && apt-get install -y \
...packages-you-want-to-install... \
&& rm -rf /var/lib/apt/lists/*
@yjcrocks
yjcrocks / convert.py
Last active September 13, 2018 10:41
camel case to snake case, snake case to camel case
# https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case
camel_re_check = re.compile(r"^(?:[A-Z][a-z]*)+$")
camel_re_substitute = re.compile(r"((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))")
is_camel = lambda x: bool(camel_re_check.match(x))
camel_to_snake = lambda x: camel_re_substitute.sub(r"_\1", x).lower()
# https://stackoverflow.com/questions/4303492/how-can-i-simplify-this-conversion-from-underscore-to-camelcase-in-python
snake_re_check = re.compile(r"((^|_+)[a-z0-9]*)*$")
snake_re_substitute = re.compile(r"(?!^)_([a-zA-Z])")
is_snake = lambda x: bool(snake_re_check.match(x))