← Tất cả bài viết

Useful stuffs

Useful Websites

Website SEO

Pagespeed Insight (https://pagespeed.web.dev/): Tool đánh giá chỉ ra vấn đề website đang gặp phải.
Google Search Console (https://search.google.com/): Tool theo dõi performance và ranking website. Xem các url nào đã được đánh index.

Study

Libgen (https://www.libgen.is/): Download sách free
Scihub (https://www.sci-hub.se/): Download paper và article free

Utility

Google Contacts (https://contacts.google.com/): Quản lý danh bạ Google, sync contact giữa các thiết bị.
Google Calendar (https://calendar.google.com/): Quản lý lịch. Có thể bật gợi nhắc ngày sinh nhật từ Google Contacts.
Codebeautify highlighter (https://codebeautify.org/code-highlighter): Online syntax highlighter
DBDiagram (https://dbdiagram.io/): Giúp drawn database. Có thể import file MySQL và export lệnh tạo MySQL. Mình dùng để vẽ database tự động khi import file MySQL và sửa lại lệnh tạo table khi thay đổi cấu trúc database.
Google Gemini (https://gemini.google.com/app): Google Chatbot. Trả lời khá OK. Có thể đưa nhiều link đọc tham khảo.
Jira Atlassian (https://www.atlassian.com/software/jira): Kanban Board. Mình dùng để note việc cần làm theo queue.

Useful commands

Script cài MySQL
sudo wget https://repo.mysql.com/mysql-apt-config_0.8.29-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.29-1_all.deb
sudo apt-get update
sudo apt-get install mysql-server -y
sudo rm mysql-apt-config_0.8.29-1_all.deb
Dump MySQL databases
mysqldump -u root -p --all-databases > all_data.sql
Load MySQL databases
mysql -u root -p < all_data.sql
Tạo ssh key
ssh-keygen
Remove known key from IP SSH
ssh-keygen -R <host>
Liệt kê các service đang chạy Linux
systemctl --type=service --state=running
Liệt kê toàn bộ process đang chạy Linux
ps -A
Tạo cert thủ công certbot
certbot certonly --manual --preferred-challenges=dns
Firewallcmd Command
firewall-cmd --list-all
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --remove-port=80/tcp --permanent
firewall-cmd --list-ports
Git Command
git checkout -b <branch-name>
git push origin -u <branch-name>
SSH Port forwarding
ssh -L <local-port>:<remote-host>:<remote-port> <user-name>@<host-name>
Tar command
tar -cvf <archive-name.tar> folder-name/ #c - create, v - verbose, f - file
MongoDB Command
mongosh "mongodb://<user-name>:<password>@localhost:27017" # Connect to DB
use <db-name> # Use DB
db.<collection-name>.find() # Show all data in collection
db.<collection-name>.drop() # Drop collection
 
use admin
db.auth("username", "password") # Authenticate
 
db.<collection-name>.find({<field-name>: <value>}) # Show data with condition
db.<collection-name>.insertOne({<field-name>: <value>}) # Insert data
db.<collection-name>.updateOne({<field-name>: <value>}, {$set: {<field-name>: <value>}}) # Update data
db.<collection-name>.deleteOne({<field-name>: <value>}) # Delete data
mongodump --db <db-name> --username <user-name> --password <password> --authenticationDatabase=admin # Backup DB
mongorestore --db <db-name>  --username <user-name> --password <password> --authenticationDatabase=admin <path-to-backup> # Restore DB
Import CSV to MongoDB
Prepare Your CSV File

The CSV file have headers, for example:

name,age,city
Alice,25,New York
Bob,30,San Francisco
Charlie,28,Los Angeles

Let's assume the file is named data.csv.

Import Data with mongoimport

Run the command:

mongoimport --uri="mongodb://localhost:27017" --db mydatabase --collection users --type csv --file data.csv --headerline

Explanation:

  • --uri="mongodb://localhost:27017": Connects to MongoDB locally.
  • --db mydatabase: Specifies the database.
  • --collection users: Defines the collection to import into.
  • --type csv: Specifies the file type.
  • --file data.csv: Points to the CSV file.
  • --headerline: Uses the first line as field names (headers).
Verify the Import

Open MongoDB shell:

mongosh

Check your imported data:

use mydatabase
db.users.find().pretty()
Curl Flags
FlagDescription
-X / --requestSpecify the HTTP method (e.g., GET, POST, PUT, DELETE).
-d / --dataSend data in a POST request.
-H / --headerPass custom headers with the request.
-o / --outputSave the response to a file.
-OSave the response to a file using the remote name.
-L / --locationFollow redirects.
-i / --includeInclude HTTP response headers in the output.
-IFetch the headers only (like a HEAD request).
-s / --silentSilent mode (no progress bar or error messages).
-S / --show-errorShow error messages when -s is used.
-f / --failFail silently (no output) on HTTP errors.
-u / --userSpecify user credentials for authentication.
-k / --insecureAllow connections to SSL sites without certificates.
Utility Script
readlink <pod-name> # follow the symbolic link and see where it point
> <file-name> # Delete all content of a file
wc -l <file-name> # Count number of lines in a file
md5sum $<file-name> # Checksum of a file on Linux
certutil -hashfile <file-name> MD5 # Checksum of a file on Windows

Most Used App

Terminus (https://termius.com/): SSH Terminal. Hỗ trợ nhiều OS
Tính năng:- Nhóm server lại quản lý

Useful Keyboard Combination MacOS

Ctrl A : Về đầu dòng

Ctrl Space ~ : Đổi input source

Click 3 lần: Bôi đen dòng

Ctrl Click dùng 1 ngón : Right click (Không dùng được khi chạy 1 số chương trình)

Click dùng 2 ngón : Right click

Microsoft Word

Ctrl + : Insert equation

Ctrl I : In nghiêng phần text trong trường hợp đang bôi đen text, bật tắt in nghiêng trong trường hợp không bôi đen

Vscode

Ctrl Shift ~ : Tạo terminal mới

Command P : Mở file

Command Shift P : Mở Command Palette

Command Shift N : Mở cửa sổ VSCode mới

Command P : Tìm file

Command W : Đóng file đang mở

Option ↑ : Di chuyển code giữa các dòng

Command ← : Về đầu dòng

Command \ : Split Terminal

Check diff giữa 2 file- Chuột phải vào tên file1, chọn Select for Compare

  • Chuột phải vào tên file2, chọn Compare with Selected
Nano text editor

Ctrl W : Text search

Vi text editor
Basic movement
  • h → Move left
  • l → Move right
  • j → Move down
  • k → Move up
  • 0 → Move to the beginning of the line
  • ^ → Move to the first non-blank character of the line
  • $ → Move to the end of the line
  • w → Move to the beginning of the next word
  • e → Move to the end of the current/next word
  • b → Move to the beginning of the previous word
  • gg → Move to the beginning of the file
  • G → Move to the end of the file
  • :n → Move to line n (e.g., :10 goes to line 10)
Search and Replace
  • /pattern → Search for pattern forward
  • ?pattern → Search for pattern backward
  • n → Repeat the last search forward
  • N → Repeat the last search backward
  • :%s/old/new/g → Replace all occurrences of old with new in the file
  • :s/old/new/ → Replace the first occurrence of old with new in the current line
File Operations
  • :w → Save (write) the file
  • :wq or ZZ → Save and quit
  • :q → Quit (fails if unsaved changes)
  • :q! → Quit without saving changes
  • :e filename → Open filename
  • :r filename → Read the contents of filename into the current file
  • :n → Open the next file in the argument list
  • :prev → Open the previous file in the argument list
Miscellaneous
  • . → Repeat the last command
  • :%!cmd → Run the file through an external command (e.g., :%!sort to sort the file)
  • Ctrl-g → Show the file name and current line/column information
  • :set number → Show line numbers
  • :set nonumber → Hide line numbers
  • :x,y → Delete from line x to line y (including y)