Zhou Tao's Learning Record

website·Indexed 29 days ago

https://zhou-tao.github.io/blog/

A technical blog by a front-end developer in Hangzhou featuring guides and notes on VuePress, Node.js (nvm, node-sass), Linux (NPM private repositories, inode, hard and soft links), JavaScript expression conversion, and algorithms including bubble sort and tree structure construction from flat data.

Tokens
9.2K
Snippets
51
Records
66
Agent score
71%

What's inside Zhou Tao's Blog

  1. Understand Linux inodes and file storage

    In Linux, files are stored in 'blocks' (typically 4KB), but their metadata is stored in an inode (index node). The system identifies files by their inode number rather than their filename; filenames are simply human-readable aliases for these numbers.

    Inode metadata includes:

    • File size in bytes
    • User ID and Group ID of the owner
    • Read, write, and execute permissions
    • Timestamps: ctime (inode change), mtime (content change), and atime (last access)
    • Link count (number of filenames pointing to this inode)
    • Pointers to the data blocks where the actual content is stored

    Key System Behaviors:

    • File Updates: Software can be updated without restarting because the system tracks the running process via the inode number. A new version can be written to a new inode under the same filename without affecting the currently executing process.
    • Inode Exhaustion: A disk can run out of space even if df -h shows available capacity if the inode table is full (common in directories with millions of tiny files). Use df -i to check inode usage.
  2. Understand Linux inodes and file storage

    In Linux, files are stored in 'blocks' (typically 4KB), while metadata is stored in an inode (index node). The system identifies files by their inode number rather than their filename. A filename is essentially a human-readable alias for an inode number.

    Inode metadata includes:

    • File size in bytes
    • User ID and Group ID of the owner
    • Read, write, and execute permissions
    • Timestamps: ctime (inode change), mtime (content change), and atime (last access)
    • Link count (number of filenames pointing to this inode)
    • Pointers to the data blocks where the actual content is stored.
  3. Recommendation to migrate from node-sass to dart-sass

    Avoid using node-sass for new projects. The official recommendation is to use dart-sass as the Sass compilation tool, as node-sass is prone to installation issues and is considered legacy.
  4. Install and initialize a VuePress v2 project

    To set up a new VuePress v2 project, create a project directory, initialize it with a package manager, and install vuepress@next as a development dependency. You must also configure scripts in package.json to handle development and build processes.
    # 1. Create and enter a new directory
    mkdir vuepress-starter
    cd vuepress-starter
    
    # 2. Initialize project
    git init
    yarn init
    
    # 3. Install VuePress v2 as a local dependency
    yarn add -D vuepress@next
    
    # 4. Add scripts to package.json
    # Add the following to your package.json:
    # "scripts": {
    #   "docs:dev": "vuepress dev docs",
    #   "docs:build": "vuepress build docs"
    # }
    
    # 5. Ignore temporary and cache directories
    echo 'node_modules' >> .gitignore
    echo '.temp' >> .gitignore
    echo '.cache' >> .gitignore
    
    # 6. Create the first document
    mkdir docs
    echo '# Hello VuePress' > docs/README.md
    
    # 7. Start the local development server
    yarn docs:dev
  5. Install and initialize a VuePress v2 project

    To set up a new VuePress v2 project, create a directory, initialize the project, and install VuePress as a development dependency. You must also configure scripts in package.json to run the development server and build the site.
    # 1. Create and enter a new directory
    mkdir vuepress-starter
    cd vuepress-starter
    
    # 2. Initialize project
    git init
    yarn init
    
    # 3. Install VuePress v2 as a local dependency
    yarn add -D vuepress@next
    
    # 4. Add scripts to package.json
    # Add the following to your package.json:
    # "scripts": {
    #   "docs:dev": "vuepress dev docs",
    #   "docs:build": "vuepress build docs"
    # }
    
    # 5. Ignore temporary and cache directories
    echo 'node_modules' >> .gitignore
    echo '.temp' >> .gitignore
    echo '.cache' >> .gitignore
    
    # 6. Create the first document
    mkdir docs
    echo '# Hello VuePress' > docs/README.md
    
    # 7. Start the local development server
    yarn docs:dev
  6. Migrate from node-sass to dart-sass

    The node-sass package is deprecated and prone to installation issues. Unless working on a legacy project that strictly requires it, it is recommended to use the official dart-sass implementation as the Sass compilation tool.
  7. Create and manage soft links (symbolic links)

    A soft link (symbolic link) is a separate file that contains the path to another file or directory. It has its own unique inode. If the original source file is deleted, the soft link remains but becomes 'broken' (pointing to a non-existent path).

    Key Characteristics:

    • Can cross different file systems/partitions.
    • Can link to directories.
    • Does not increment the link count of the target inode.
    # Create a soft link
    ln -s [source_file_or_dir] [target_link]
  8. Install Node.js on Linux for NPM Registry

    To set up a private NPM registry, you first need a Node.js environment. This involves downloading the binary, extracting it, and configuring the system PATH.
    # Download Node.js binary
    wget https://npmmirror.com/mirrors/node/v16.14.2/node-v16.14.2-linux-x64.tar.xz
    
    # Extract the archive
    tar -zxv node-v16.14.2-linux-x64.tar.xz
    
    # Add to environment variables in /etc/profile
    # Replace /.../ with your actual installation directory
    vi /etc/profile
    # Add this line to the end of the file:
    export PATH=$PATH:/.../node-v16.14.2-linux-x64/bin
    
    # Apply changes
    source /etc/profile
    
    # Verify installation
    node -v
    npm -v
  9. Create and manage soft links (symbolic links)

    A soft link (symbolic link) is a separate file that contains the path to another file or directory. It acts as a shortcut.

    Characteristics:

    • Path-based: Points to a filename/path, not an inode number. The target's inode link count does not increase.
    • Dependency: If the original target file is deleted, the soft link becomes 'broken' and returns a "No such file or directory" error.
    • Flexibility: Can link to directories and can span across different file systems/partitions.

    Usage:

    # Create a soft link
    ln -s [source_file_or_dir] [target_link]
  10. Create a professional resume using Markdown and MarkText

    To create a resume that maintains a professional appearance (avoiding the crude default styles of basic Markdown PDF exports), use the following workflow: 1. Write the resume in a Markdown editor (MarkText is recommended as it is open-source and free). 2. Export the document to HTML to allow for CSS styling. 3. Apply custom CSS to the HTML file to refine colors, margins, and spacing. 4. Use a web browser's print-to-PDF functionality for the final output.
  11. Export styled HTML resume to PDF via Chrome

    Once the HTML resume is styled, use Google Chrome to generate the final PDF: 1. Open the HTML file in Chrome. 2. Press Ctrl+P or right-click and select 'Print'. 3. In the print preview, adjust the margins as needed. 4. Change the 'Destination' (target printer) to 'Save as PDF'. 5. Click 'Save'.
  12. Resolve node-sass installation errors on Windows

    When installing node-sass in legacy projects on Windows, installation often fails due to missing build dependencies. To resolve this, you must install Python 2.7 and configure npm to use that specific Python installation directory.