Linux

FFmpeg with Nvidia GPU on Ubuntu 20.04

Prep - Install Nvidia driver and cuda-toolkit I installed on Ubuntu 20.04. Install https://developer.nvidia.com/ffmpeg git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git cd nv-codec-headers && sudo make install && cd – git clone https://git.ffmpeg.org/ffmpeg.git cd ffmpeg #export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig" sudo apt install -y pkg-config ./configure --enable-cuda-sdk --enable-cuvid --enable-nvenc --enable-nonfree --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64 make -j 10 Error 1 /usr/local/cuda-10.2/bin/../targets/x86_64-linux/include/crt/host_config.h:138:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported! 138 | #error -- unsupported GNU version!

Set up Ubuntu 20.04 server with Nvidia GPU (and spaCy)

After OS install - basical update Upgrade softwares sudo su apt update apt upgrade -y ssh hardening ssh user@newserver.com mkdir .ssh chmod 700 .ssh #copy id_ecdsa.pub in .ssh/authorized_keys chmod 600 .ssh/authorized_keys In /etc/ssh/sshd_config add the following configurations. PermitRootLogin no PubkeyAuthentication yes PasswordAuthentication no After configuration, restart sshd. sudo systemctl restart sshd sudo su passwd # Change root passwd Firewall - ufw https://ubuntu.com/engage/20.04-webinars This comes through the constant security patching process and new features like the Ubuntu Server Live installer, iptables to nftables migration, and more resilient boot loader.

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' : '~/.

iptables

Concept of iptables It is a realy rule table in which the IP communication rules are. There are groups of these rules, and it’s called “chain'. iptables configuration Configuration file You can see the configurations in the file /etc/iptables/rule.v4. Here is a sample line in the file. -A chain-outgoing-services -s 192.168.100.50/32 -d 1.2.3.4/32 -p tcp -m tcp --dport 22 -m comment --comment "This is a comment." -j ACCEPT http://web.mit.edu/rhel-doc/4/RH-DOCS/rhel-rg-en-4/s1-iptables-options.html -A chain-outgoing-services: Append the rule to chain chain-outgoing-services.

Kernel parameters for hardening

/etc/security/limits.conf Concept https://wiki.archlinux.org/index.php/Limits.conf /etc/security/limits.conf allows setting resource limits for users logged in via PAM. This is a useful way of preventing, for example, fork-bombs from using up all system resources. Note: The file does not affect system services. For systemd services the files /etc/systemd/system.conf, /etc/systemd/user.conf, and /etc/systemd/<systemd_unit>/override.conf control the limit. See the systemd-system.conf(5) man page for details. Config sample https://linux.die.net/man/5/limits.conf * soft nofile 160000 The syntax of the lines is as follows:

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.

Regular expressionexp - snippets

Regular expression Regular expression is a basic concept in theoretical computer science. Once you see the Wikipedia page of “Regular expression”, you can realize how important it is for understanding computer science. But for beninner of web engineer, the simple explanation of regular expression could be, it is just a “pattern” in a nut shell. Regular expression is often abbreviated to regex. Regex rules (To be updated…) Here is often used regex syntax.