Roy Fuwei's Documentation and Blog

website·Indexed 31 days ago

https://royfuwei.dev

A collection of technical notes and guides covering Node.js, Go, Nx Monorepo, Kubernetes (k8s) with Lens, PostgreSQL, and Docusaurus. Includes practical tips on process management in Node.js, slice pointers in Go, and CI/CD architecture.

Tokens
5K
Snippets
36
Records
53
Agent score
51%

What's inside Roy Fuwei's Dev Notes

  1. Understand Kubernetes Cluster Architecture

    Kubernetes uses a Master-Slave architecture to manage containerized applications. The hierarchy is structured as follows:

    • Cluster: Consists of one MasterNode and multiple WorkerNodes.
    • Node: Represents a physical or virtual machine.
    • Pod: An abstraction layer that can contain one or more Containers and Volumes. Pods share a network namespace (localhost).
    • Container: An instance of an Image (which is a template of an OS + App).
  2. Create and organize blog posts in Docusaurus

    Docusaurus blogging features are powered by the @docusaurus/plugin-content-blog plugin. To create blog posts, add Markdown files or folders to the blog directory. To co-locate images with a specific post, use a folder structure for that post. Blog post dates are automatically extracted from filenames using the format YYYY-MM-DD-title.md or by placing an index.md inside a folder named YYYY-MM-DD-title.
    # Example filename for date extraction
    2019-05-30-welcome.md
    
    # Example folder structure for co-locating images
    2019-05-30-welcome/
    ├── index.md
    └── image.jpg
  3. Use Mermaid diagrams in Docusaurus

    Docusaurus supports Mermaid diagrams natively. For detailed syntax and implementation, refer to the official Mermaid documentation and the Docusaurus markdown-features guide.
  4. Automate versioning and changelog generation with standard-version

    Use standard-version to automatically bump the package version and generate a CHANGELOG.md file based on conventional commit messages. This requires conventional-changelog dependencies.
    "devDependencies": {
        "conventional-changelog-angular": "^5.0.13",
        "conventional-changelog-cli": "^2.2.2"
    }
  5. Monitor Kubernetes node resources using Lens

    Lens provides monitoring capabilities for Kubernetes nodes (CPU, Memory, and Disk usage) by utilizing the node-exporter located within the lens-metrics namespace.
  6. Limit blog post length in list view using truncate comment

    To limit the amount of content displayed for a blog post in the list view, insert the <!-- truncate --> HTML comment at the point where the content should be cut off.
    This is the summary that will appear in the list view.
    
    <!-- truncate -->
    
    This content will be hidden in the list view and only visible on the full post page.
  7. Set up and manage blog posts in Docusaurus

    Docusaurus blogging features are powered by the @docusaurus/plugin-content-blog plugin. To create blog posts, add Markdown files or folders to the blog directory. Blog post dates are automatically extracted from filenames using the format YYYY-MM-DD-title.md (e.g., 2019-05-30-welcome.md) or from an index.md file within a dated folder (e.g., 2019-05-30-welcome/index.md). Using a folder for a post allows for easier co-location of images.
  8. Set up Commitizen for interactive commit prompts

    Commitizen provides a CLI tool to help developers write conventional commit messages through an interactive prompt. It integrates with commitlint and husky to automate the process.
    # Install dependencies
    npm install commitizen --save-dev
    npm install @commitlint/cz-commitlint --save-dev
    
    # Initialize husky
    npx husky-init && npm install
    
    # Add the prepare-commit-msg hook to trigger Commitizen
    npx husky add .husky/prepare-commit-msg 'exec < /dev/tty && node_modules/.bin/cz --hook || true'
    // Add to package.json
    "config": {
        "commitizen": {
            "path": "@commitlint/cz-commitlint"
        }
    }
  9. Create and manage blog posts in Docusaurus

    Docusaurus blogging features are powered by the @docusaurus/plugin-content-blog plugin. To create blog posts, add Markdown files or folders to the blog directory.

    Post dates are automatically extracted from filenames using the format YYYY-MM-DD-title.md (e.g., 2019-05-30-welcome.md) or from an index.md file within a folder named with the date (e.g., 2019-05-30-welcome/index.md). Using a folder for a post allows you to co-locate images with the content. Blog authors can be managed in the authors.yml file, and posts support tags.

  10. Filter PostgreSQL boolean columns for both False and Null values

    When a boolean column allows NULLs, using != true or NOT IN (true) will fail to return rows where the value is NULL because NULL comparisons result in UNKNOWN. To retrieve both false and null records, use an explicit OR condition with IS NULL.
    -- This will NOT return NULL values
    SELECT * FROM foo WHERE ignored != true;
    SELECT * FROM foo WHERE ignored NOT IN (true);
    
    -- Correct way to get both False and Null
    SELECT * FROM foo WHERE ignored = false OR ignored IS NULL;
  11. Use MDX in Docusaurus blog posts for interactivity

    Docusaurus blog posts support MDX, allowing you to embed React components directly within markdown content to create interactive posts.
    <button onClick={() => alert('button clicked!')}>Click me!</button>