Sấu Gấu's Blog


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

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>
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:

Verify the Import

Open MongoDB shell:

mongosh

Check your imported data:

use mydatabase
db.users.find().pretty()
Curl Flags
Flag Description
-X / --request Specify the HTTP method (e.g., GET, POST, PUT, DELETE).
-d / --data Send data in a POST request.
-H / --header Pass custom headers with the request.
-o / --output Save the response to a file.
-O Save the response to a file using the remote name.
-L / --location Follow redirects.
-i / --include Include HTTP response headers in the output.
-s / --silent Silent mode (no progress bar or error messages).
-S / --show-error Show error messages when -s is used.
-f / --fail Fail silently (no output) on HTTP errors.
-u / --user Specify user credentials for authentication.
-k / --insecure Allow 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ý
  • SSH theo user
  • Split screen
  • Drag item từ các server với nhau
  • Thay key ssh nếu thấy host thay đổi
  • Visual Studio Code (https://code.visualstudio.com): IDE phổ biến nhất
    Telegram (https://desktop.telegram.org): App nhắn tin

    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
    Search and Replace
    File Operations
    Miscellaneous

    Ngày đăng: April 5, 2024
    384 total views

    Comment

    anonymous: yo