Skip to content

Instantly share code, notes, and snippets.

View mjhong0708's full-sized avatar

Minjoon Hong mjhong0708

  • Yonsei University
  • Seoul, Korea
View GitHub Profile
@mjhong0708
mjhong0708 / pad_and_collate.py
Created June 14, 2021 05:42
PINN torch code snippets
class CollateTensors:
"""
Pads and collates multidimensional tensors with variable length in a batch, according to maximum length.
Adapted from https://discuss.pytorch.org/t/dataloader-for-various-length-of-data/6418/8
"""
def __init__(self, dim=0):
"""
:param dim: the dimension to be padded (dimension of time in sequences)
"""
@mjhong0708
mjhong0708 / init.vim
Last active June 26, 2021 14:35
My init.vim for python development
filetype plugin indent on
autocmd FileType py setlocal tabstop=4 shiftwidth=4 expandtab
set number
call plug#begin('~/.local/share/nvim/site/plugged')
" nvim-yarp
Plug 'roxma/nvim-yarp'
" NCM2

Synology NAS를 linux에 마운트하기

1. SMB 사용하기

먼저 cifs-utils를 설치한다.

sudo apt install cifs-utils

이제 /etc/fstab을 열어서 부팅 시 자동으로 폴더를 mount 되게 만들어야 한다. 그 전에, 마운트할 경로는 미리 만들어야 한다. 주의할 것은, fstab에서 공백은 모두 tab이다.

@mjhong0708
mjhong0708 / gotojob.sh
Last active September 14, 2021 06:16
gotojob
function gotojob {
if (( $# == 0 )); then
echo "gotojob v0.1.0 by Minjoon Hong"
echo "change current directory to working directory of a slurm job"
echo "usage: $FUNCNAME [SLURM_JOBID]"
return
fi
workdir=$(scontrol show job $1 | grep Dir | awk -F '=' '{print $2}')
cd $workdir
}
@mjhong0708
mjhong0708 / minorticks.py
Last active August 3, 2022 06:10
matplotlib_number of minorticks
import matplotlib.ticker
class MyLocator(matplotlib.ticker.AutoMinorLocator):
def __init__(self, n=2):
super().__init__(n=n)
matplotlib.ticker.AutoMinorLocator = MyLocator
@mjhong0708
mjhong0708 / mp4_from_images.sh
Created November 28, 2021 15:02
Generate video from images with ffmpeg
# ffmpeg -framerate $frame_rate -i $filename_pattern $output_filename
# example)
ffmpeg -framerate 30 -i filename-%03d.jpg output.mp4
@mjhong0708
mjhong0708 / view_atoms.py
Created December 22, 2021 04:23
Plot atoms on matplotlib
import ase.io
from ase.visualize.plot import plot_atoms
import matplotlib.pyplot as plt
import matplotlib_inline
def view_atoms(atoms):
fig, axs = plt.subplots(nrows=1, ncols=3, facecolor="w", dpi=130)
axs[0].set_title("Top", fontfamily="Arial", fontsize=16, fontweight="bold")
axs[1].set_title("Side", fontfamily="Arial", fontsize=16, fontweight="bold")
@mjhong0708
mjhong0708 / keras_like_progressbar.py
Last active December 30, 2021 06:30
Show keras-like progress bar on pytorch
def make_progbar(num_done, total_length):
num_done_syms = int((num_done + 1) / total_length * 30)
if total_length > 1 and num_done == 0:
progbar = "[" + ">".ljust(30, ".") + "]"
elif num_done < total_length - 1:
progbar = "[" + "=" * num_done_syms + ">".ljust(30 - num_done_syms, ".") + "]"
else:
progbar = "[" + ">".rjust(30, "=") + "]"
return progbar
@mjhong0708
mjhong0708 / ase_db_psi4.ipynb
Last active January 22, 2022 13:03
ase db & psi4
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mjhong0708
mjhong0708 / incar.py
Last active January 26, 2022 01:26
Simple INCAR parser class
from typing import Iterable, Union
Numeric = Union[int, float]
IncarValue = Union[bool, str, Numeric, Iterable[Union[str, Numeric]]]
class Incar:
def __init__(self, **kwargs):
self.__dict__ = kwargs