Skip to main content
Hieu Nguyen
Senior Software Engineer
View all authors

Things to Do After Installing Ubuntu

· 2 min read
Hieu Nguyen
Senior Software Engineer

Things to Do After Installing Ubuntu

In this post, I want to share the things I usually do after installing Ubuntu.

Update and upgrade package

Update and upgrade your system to keep your software up to date.

sudo apt update

sudo apt upgrade -y

Remove unused packages

This command helps clean up unused packages and free disk space.

sudo apt autoremove

Install compilation tools

Install the basic compilation tools required to build software from source.

# Install essential build tools (gcc, make, etc.)
sudo apt install build-essential

# check
gcc --version
g++ --version

Install network tool

Provides legacy networking commands such as ifconfig and netstat

# Install network utilities like ifconfig, netstats
sudo apt install net-tools

# check ip
ifconfig

Install firewall

Install a user-friendly firewall tool to helps secure your Ubuntu system and control incoming and outgoing network traffic.

# Install UFW firewall
sudo apt install ufw

# Check status firewall
sudo ufw status verbose

# If you use SSH remotely, allow SSH before enabling the firewall
sudo ufw allow ssh # (skip this step if you are using Ubuntu as a desktop client)

# enalbe firewall
sudo ufw enable

# Control ufw via GUI
sudo apt install gufw

Other Useful Tools

## Optional but Recommended

# Install Git
sudo apt install git

# Config git
git config --global user.name "Your Name"
it config --global user.email "your.email@example.com"

# Install curl, wget
sudo apt install curl
sudo apt install wget

Thanks for reading, I hope you find this helpful.

Intro Vim editor - Lazy Vim

· 5 min read
Hieu Nguyen
Senior Software Engineer

What is Vim?

Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient. It is included as "vi" with most UNIX systems and with Apple OS X.

What is the LazyVim?

LazyVim is a Neovim setup powered by 💤 lazy.nvim to make it easy to customize and extend your config.

What is Tmux?

Tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal.

Installation

Install Nvim

Nvim is based on Vim by Bram Moolenaar. Nvim is emphatically a fork of Vim, not a clone: compatibility with Vim (especially editor and Vimscript features, except Vim9script) is maintained where possible. See vim-differences for the complete reference.

Install Nvim

On Linux

curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim-linux-x86_64.tar.gz

sudo rm -rf /opt/nvim-linux-x86_64

sudo tar -C /opt -xzf nvim-linux-x86_64.tar.gz

Add to file ~/.bashrc


export PATH="$PATH:/opt/nvim-linux-x86_64/bin"

Check again

nvim --version


# Output

NVIM v0.11.4
Build type: Release
LuaJIT 2.1.1741730670
Run "nvim -V1 -v" for more info

Install LazyVim

Install LazyVim

Backup old Neovim

# required
mv ~/.config/nvim{,.bak}

# optional but recommended
mv ~/.local/share/nvim{,.bak}
mv ~/.local/state/nvim{,.bak}
mv ~/.cache/nvim{,.bak}

Install Lazzy Vim

git clone https://github.com/LazyVim/starter ~/.config/nvim

rm -rf ~/.config/nvim/.git

Start Neovim, and waitin to LazyVim finish setup.

nvim

Install Tmux

Install Tmux

On debian

sudo apt install tmux

Install Tmux Plugin Manager. Custome your tmux (if you need or skip -> jump to next step, it not required)

Install Tmux Plugin Manager

My config tmux. You can copy and put to file ~/.tmux.conf or reference at tmux-plugin

# .tmux.conf

set -g default-terminal 'screen-256color'
set -g status-style 'bg=#1e1e2e'

setw -g mode-keys vi
bind-key h select-pane -L
bind-key j select-pane -D
bind-key k select-pane -U
bind-key l select-pane -R

bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r H resize-pane -L 5
bind -r L resize-pane -R 5

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'github_username/plugin_name#branch'
# set -g @plugin 'git@github.com:user/plugin'
# set -g @plugin 'git@bitbucket.com:user/plugin'

# theme
set -g @plugin 'dracula/tmux'
# set -g @dracula-plugins 'cpu-usage ram-usage'
# set -g @dracula-cpu-usage-colors 'pink dark-gray'
set -g @dracula-show-powerline true
set -g @dracula-show-flags true
set -g @dracula-show-left-icon session
set -g @dracula-cpu-display-load true
set -g @dracula-plugins "cpu-usage ram-usage"
# per default available colors: white, gray, dark_gray, light_purple, dark_purple, cyan, green, orange, red, pink, yellow
# set -g @dracula-[plugin-name]-colors "[background] [foreground]"
set -g @dracula-cpu-usage-colors "pink dark_gray"
# the default is 5, it can accept any number
set -g @dracula-refresh-rate 5
set -g @dracula-border-contrast true
set -g @dracula-transparent-powerline-bg true
# default is 1, it can accept any number and 0 disables padding.
set -g @dracula-left-icon-padding 0
set -g @dracula-show-battery-status true
set -g @dracula-time-format "%F %R"
set -g status-position top


# neovim
set -g @plugin 'christoomey/vim-tmux-navigator'

set -g @vim_navigator_mapping_left "C-Left C-h" # use C-h and C-Left
set -g @vim_navigator_mapping_right "C-Right C-l"
set -g @vim_navigator_mapping_up "C-k"
set -g @vim_navigator_mapping_down "C-j"
set -g @vim_navigator_mapping_prev "" # removes the C-\ binding

set -g @vim_navigator_prefix_mapping_clear_screen ""


set -g @plugin 'laktak/extrakto'
set -g @plugin 'rickstaa/tmux-notify'
set -g @plugin 'sainnhe/tmux-fzf'
set -g @plugin 'AngryMorrocoy/tmux-neolazygit'

## config auto reopen session
#set -g @plugin 'tmux-plugins/tmux-resurrect'
#set -g @plugin 'tmux-plugins/tmux-continuum'

#set -g @continuum-restore 'on'
#set -g @continuum-boot 'on'


# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

On Terminal

Start tmux

tmux 

Ctrl b -> Shift + i => To install plugin Ctrl b -> Shift + u -> all -> To update all plugin

Ctrl b: is default prefix. You can change with config

# ~/.tmux.conf
# remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix

Basic

Keymaps

Keymaps

Plugin

Plugin

Config Nvim for tmux

# ~/.config/nvim/lua/plugins

return {
{
"christoomey/vim-tmux-navigator",
cmd = {
"TmuxNavigateLeft",
"TmuxNavigateDown",
"TmuxNavigateUp",
"TmuxNavigateRight",
"TmuxNavigatePrevious",
"TmuxNavigatorProcessList",
},
keys = {
{ "<c-h>", "<cmd><C-U>TmuxNavigateLeft<cr>" },
{ "<c-j>", "<cmd><C-U>TmuxNavigateDown<cr>" },
{ "<c-k>", "<cmd><C-U>TmuxNavigateUp<cr>" },
{ "<c-l>", "<cmd><C-U>TmuxNavigateRight<cr>" },
{ "<c-\\>", "<cmd><C-U>TmuxNavigatePrevious<cr>" },
},
},
}

Install plugin for nvim

nvim

# Press l -> Shift u -> Shift s


Why I choose LazyVim and Tmux?

Thank for reading!

100 Days Leetcode - Day 1

· 2 min read
Hieu Nguyen
Senior Software Engineer

Day 1 - Contains Duplicate

Description

Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.


Example 1:
Input: nums = [1, 2, 3, 1]
Output: false

Example 2:
Input: nums = [1, 2, 3, 4]
Output: false

Example 3:
Input: nums = [1, 1, 1, 3, 3, 4, 3, 2 , 4, 2]
Output: true

Constraints:
1 <= nums.length <= 10^5
-10^9 <= nums[i] <= 10^9

Solution

Approach 1 - Sorting

Step 1: We will sort the array nums. If two numbers are the same, they will be placed next to each other. Step 2: We just need to check whether the two adjacent numbers are equal or not.

class Solution {
public boolean containsDuplicate(int[] nums) {
Arrays.sort(nums);

for (int i = 0; i < nums.length; ++i) {
if (nums[i] == nums[i - 1]) {
return true;
}
}

return false;
}
}

Complexity:

Time
sort => Dual-Pivot Quicksort O(n log n)
for => O(n)

Result: O(n log n + n) = O(n log n)

Space
O(1)

Approach 2 - HashSet

We create a Set and add each element of the nums array into the set. If the insertion fails, it means the element is duplicated, and we return true. Otherwise, if we finish checking the entire array without any failure, it means the array has no duplicated.

class Solution {
public boolean containsDuplicate(int[] nums) {
Set<Integer> setNums = new HashSet<>();
for (int num : nums) {
if (!setNums.add(nums)) {
return true;
}
}
return false;
}
}


Complexity

Time
for => O(n)

Space
Set => O(n)

Thank for reading!