tips

Newtype Pattern, Avoid String Parameter in Strongly-Typed Languages

Why? String type has generally lots of choices for the values, so it prones to bugs. If your programing language supports strong-typing, you need to consider avoiding Strings as parameters of functions. Strong-typing led you Less bugs and validations. In Rust, it’s called a “newtype pattern”. The trinity, “Good naming (based on DDD) + good typing (struct) + enum”, helps us always. Newtype patterns in Rust https://doc.rust-lang.org/book/ch19-03-advanced-traits.html use std::ops::Add; struct Millimeters(u32); struct Meters(u32); impl Add<Meters> for Millimeters { type Output = Millimeters; fn add(self, other: Meters) -> Millimeters { Millimeters(self.

Small tip: Multi aws-cli environment

Motivation If you use multi AWS accounts in your work environment, I hightly recommend to configure your “aws-cli profile” so that you can easily change your aws-cli account. The only thing you need to do when you want to change your aws-cli environment is the option --profile. Very simple. How to configure https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html Check under ~/.aws/. You can configure multi profile.

Set up my Vim

Install jellybeans I use a color scheme called “Jellybeans”. mkdir ~/.vim cd ~/.vim sudo yum install -y git git clone https://github.com/nanotech/jellybeans.vim mkdir colors mv jellybeans.vim/colors/jellybeans.vim ~/.vim/colors/jellybeans.vim vim ~/.vimrc colorscheme jellybeans set expandtab set tabstop=2 set softtabstop=2 set shiftwidth=2 set number syntax on set t_Co=256 set foldmethod=syntax Add the line into ~/.bashrc, TERM=xterm-256color vim plugin manager https://github.com/junegunn/vim-plug/wiki/tips#automatic-installation Add the following in .vimrc: let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.

Reference your own contents in Hugo

https://gohugo.io/content-management/cross-references/#use-ref-and-relref Refer another post Please delete a backquote (\) in the follwoing snippet. I added it because of a Hugo rendering issue. [text to be hyperlinked]({\{< ref "hugo/article.md" >}}) You don’t need to append contents in the reference. When you open this hugo document in local hugo server the link is referred as http://localhost:1313/hugo/article. When you open this hugo document on the hosted server, the link is referred as http://{{ your_base_URL_in_config.

NLP tools in Python

Libraries I need a few libraries for NLP and each of them are very powerful. I downloaded all of these libraries via pip, like pip install -U {package}. In the last section, I summaraized the libraries and I can install them at once later. spaCy: Open source NLP library. NLTK: Natural Language ToolKit. It is older than spaCy (spaCy 2015~, NLTK 2001~). gensim: NLP tools. I installed it for Doc2Vec. TensorFlow: For custom models of machine learning including Keras.

Linux CLI snippets

for loop of all files in a directory The following snippet shows all files in Loop_dir. Loop_dir="path_to_dir" for entry in "$Loop_dir"/* do echo "$entry" done cf) https://stackoverflow.com/questions/13210880/replace-one-substring-for-another-string-in-shell-script/13210909 Check argument is set or not https://www.cyberciti.biz/faq/unix-linux-bash-script-check-if-variable-is-empty/ process tree ps -aef —forest Find from all files in the directory Find all lines from files in the current directory find ./ -type f -print | xargs grep 'foo' I created my custom alias. alias afind="find -type f -print | xargs grep" Delete prefix of files in a directory Here is a pioneer.

rsync (Draft)

Why rsync not SCP It can restart download (fragmentation method?). Download a file from remote Download a folder from remote (@rsync_dir) rsync -avzhP remote_user@remote.com:/path/to/dir ./ -a: archive -h: human redable output -z: compress (like zip) data during the transfer -v: verbose -P: –partial + –progress Sync - upload a current structure under the remotedir In dir, rsync -ahzv ./* remote-user@remote.com:/path/to/dir/ It will overwrite the same name file!!` Skip (almost) same contents --size-only skips files that match in size.

Tips for Ansible

Before installing via pip (in WSL) sudo apt install libffi-dev Debugging step by step Run a playbook with option --step. Pipe (|) in variable It is called “filter”. https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#product-filters when, and, or, not https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html Group restriction If you have a large amount of servers in inventories, -l option can restrict the target of playbook. -l Server_group_name -l FQDN What ever the system use systemd or initd When your environment has different OSs, systemd module doesn’t work sometimes.

Set posts template in Hugo project

Tips - Change the template which generated by hugo new You can define a template in the file archetypes/default.md. Here is my sample. --- title: "{{ replace .Name "-" " " | title }}" date: {{ .Date }} categories: - "Draft" tags: - "dummy_tag" isCKJLanguage: false mathjax: false comments: false draft: true ---

Highlight code block in Hugo

Highlight codes in Hugo - It’s changed Old Hugo Around a year ago (2019), we need to configure pygments in order to highlight codes in code block. Here are sample lines in config.toml file. ... pygmentsCodefences = true pygmentsCodefencesGuessSyntax = true pygmentsStyle = "monokai" ... Latest Hugo (2020) At the new version Hugo in 2020, Hugo officially supports code highlight as a default as a default. Official syntax highlighting: https://gohugo.io/content-management/syntax-highlighting/#highlighting-in-code-fences