Skip to content

Instantly share code, notes, and snippets.

View joonahn's full-sized avatar

Seokjoon Ahn joonahn

  • POSTECH
  • Pohang
View GitHub Profile
@joonahn
joonahn / create_cube_rotation.py
Created November 5, 2021 09:05
create 24 unique 3x3 cube rotation matrices.
# the algorithm is from https://stackoverflow.com/questions/16452383/how-to-get-all-24-rotations-of-a-3-dimensional-array
import nunpy as np
rollmat = np.array([[1, 0, 0], [0, 0, 1], [0, -1, 0]], dtype=np.float)
turnmat = np.array([[0, -1, 0], [1, 0, 0], [0, 0, 1]], dtype=np.float)
def get_24_rotation():
rotations = []
current_rot = np.eye(3)
@joonahn
joonahn / main.py
Created September 2, 2021 00:43
training main.py boilerplate
import argparse
def str2bool(v):
if isinstance(v, bool):
return v
if v.lower() in ('yes', 'true', 't', 'y', '1'):
return True
elif v.lower() in ('no', 'false', 'f', 'n', '0'):
return False
else:
@joonahn
joonahn / contry_name_emoji_map.py
Last active February 23, 2020 13:17
국가 이름과 국가 emoji 매핑
# usage : contries_flag_dict.get("<국가명>", "")
contries_flag_dict = {
"어센션 섬" : "🇦🇨",
"안도라" : "🇦🇩",
"아랍에미리트" : "🇦🇪",
"아프가니스탄" : "🇦🇫",
"앤티가 바부다" : "🇦🇬",
"앵귈라" : "🇦🇮",
"알바니아" : "🇦🇱",
"아르메니아" : "🇦🇲",
i=1
sp="/-\|"
echo -n ' '
while true
do
printf "\b${sp:i++%${#sp}:1}"
sleep 0.1
done
@joonahn
joonahn / SimpleHTTPServerWithUpload.py
Last active August 26, 2023 02:27 — forked from UniIsland/SimpleHTTPServerWithUpload.py
Simple Python Http Server can upload multiple files
#!/usr/bin/env python3
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
see: https://gist.github.com/UniIsland/3346170
"""
@joonahn
joonahn / generate_noise.py
Last active September 28, 2018 06:14
Code that generate random noises
import sys
import numpy as np
data = np.random.uniform(-1, 1, [int(input("input random array length:"))])
data = np.around(data, 3).tolist()
print(data)
@joonahn
joonahn / get_data.py
Created September 13, 2018 01:51
Get data from web
import requests
URL = 'http://www.tistory.com'
response = requests.get(URL)
print(response.status_code)
print(response.text)
@joonahn
joonahn / profile_python_method.md
Last active June 20, 2018 00:35
python method profile 방법

Profile python methods

python method를 profile 하는 간단한 방법에 대한 소개

Code

우선 decorator method를 정의한다. 그 뒤 profile 대상 메소드 def 위에 @profileit decorator를 붙인다.

import cProfile

def profileit(func):
 def wrapper(*args, **kwargs):
@joonahn
joonahn / repair_broken_mac_filename.py
Last active October 8, 2019 05:58
mac에서 생성한 한글 파일명을 windows에서 읽을 때 깨진 파일을 복구해 주는 스크립트
import sys
from unicodedata import normalize
import glob
import os
def nfd2nfc(data):
return normalize('NFC', data)
if len(sys.argv) > 1:
dirname = sys.argv[1]
@joonahn
joonahn / nfd2nfc.py
Created April 24, 2018 02:16
Mac에서 깨진 파일 string을 합쳐진 windows string으로 변환하는 함수
from unicodedata import normalize
def nfd2nfc(data):
return normalize('NFC', data)