Skip to content

Instantly share code, notes, and snippets.

@joongh
joongh / paths.sh
Last active September 2, 2020 04:36
Paths of current bash script
#!/bin/bash
echo $0
fullpath=$(realpath $0)
echo ${fullpath}
dirpath=$(dirname $fullpath)
echo ${dirpath}
@joongh
joongh / vimrc
Created May 24, 2018 02:09
vimrc - Check file encoding before write and change it to what you want
func! Encode_euckr()
" Don't change to euc-kr for these file formats
if &ft =~ 'py\|robot\|yaml'
return
endif
if &fileencoding != "cp949" && &fileencoding != "euc-kr"
if confirm("File encoding is not euc-kr. Change it?", "&Yes\n&No", 1) == 1
set fileencoding=euc-kr
endif
@joongh
joongh / detect_encoding.py
Created April 23, 2018 18:25
detect file encoding using the first 4 bytes of the file
def detect_encoding(file_path):
with open(file_path, 'rb') as f:
b = f.read(4)
if (b[0:3] == b'\xef\xbb\xbf'):
return 'utf-8'
if ((b[0:2] == b'\xfe\xff') or (b[0:2] == b'\xff\xfe')):
return 'utf-16'
if ((b[0:5] == b'\xfe\xff\x00\x00') or (b[0:5] == b'\x00\x00\xff\xfe')):
return 'utf-32'
return 'euc-kr' # default value
@joongh
joongh / toeplitz_based_hash.py
Last active August 16, 2023 12:09
Python implementation of Toeplitz-based hash function. It is implemented to understand how the Toeplitz-based hash function works.
#!/usr/bin/env python
#-*- coding: utf-8 -*-
# Test data including the secret key, ip, port numbers and the hash values
# as the result is from "Intel Ethernet Controller 710 Series Datasheet".
KEY=[]
def reset_key():
global KEY
@joongh
joongh / rsaencdec.py
Created January 13, 2016 08:44
Encryption, Decryption using RSA (PKCS1_v1_5) in Python
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from Crypto.Cipher import PKCS1_v1_5
from Crypto.PublicKey import RSA
from Crypto.Hash import SHA
from Crypto import Random
import base64
import StringIO
# passphrase, random string => private key, public key pair