mx52jing's Technical Notes

website·Indexed 30 days ago

https://mx52jing.github.io/static-blog/

A collection of technical notes and guides covering front-end development (CSS, Sass, Canvas, React, Taro), system administration (Linux, Mac, Nginx, Git), tool configuration (Charles), and LeetCode algorithm solutions implemented in JavaScript and TypeScript.

Tokens
100.5K
Snippets
572
Records
615
Agent score
74%

What's inside mx52jing Notes

  1. Overview of Babel core modules

    Babel's transformation process relies on several key modules:

    • Babylon: The parser that converts source code into an Abstract Syntax Tree (AST). It is a fork of Acorn designed for non-standard and future JavaScript features.
    • @babel/traverse: Maintains the state of the AST and handles the replacement, removal, and addition of nodes.
    • @babel/types: A utility library (similar to Lodash) for AST nodes, providing methods to construct, validate, and transform nodes.
    • @babel/generator: The code generator that converts an AST back into source code, including sourcemaps.
    • @babel/template: Allows developers to write code as strings with placeholders to avoid manual AST construction.
  2. Overview of Nacos core functions

    Nacos is a platform designed for dynamic service discovery, configuration, and service management, facilitating the construction of cloud-native applications and microservices platforms. Its four primary functions are:

    • Service discovery and service health checks
    • Dynamic configuration management
    • Dynamic DNS service
    • Service and metadata management
  3. Understand Docker core concepts

    Docker is built around three primary concepts:

    1. Image: A read-only, layered file system containing the resources, configurations, and parameters required to run a container. Images are immutable; changes result in new layers.
    2. Container: A runnable instance of an image. Containers are read-write layers on top of the read-only image. Data in a container is lost if the container is deleted, but persists if the container is only stopped.
    3. Repository: A collection of related images, similar to a Git repository, using tags for versioning. Examples include Docker Hub and Alibaba Cloud.
  4. Understand Vite dependency pre-bundling

    Native browser ESM only supports paths starting with /, ./, or ../. When importing third-party modules (e.g., import _ from 'lodash-es'), browsers will throw a TypeError if the file is opened directly. Vite solves this via 'Dependency Pre-bundling', where the Dev Server intercepts the request and replaces the bare module specifier with a valid path to the pre-bundled dependency.
  5. Understand Go pointer basics and operators

    In Go, a pointer is a variable that stores the memory address of another variable. A pointer to a type T has the type *T.

    There are two primary pointer operators:

    1. & (Address-of operator): Used to get the memory address of a variable.
    2. * (Dereference operator):
      • When used on the left side of an assignment, it refers to the variable the pointer points to.
      • When used on the right side of an assignment, it retrieves the value stored at the memory address (dereferencing).
    func p() {
    	x := "Hello"
    	y := &x // y stores the address of x
    	fmt.Println(x)  // Output: Hello
    	fmt.Println(*y) // Output: Hello (dereferencing y)
    	fmt.Println(&x) // Output: 0x... (memory address)
    	fmt.Println(y)  // Output: 0x... (memory address)
    }
  6. Implement a 'Belongs To' one-to-one relationship in GORM

    In a 'Belongs To' relationship, the model (A) contains the foreign key of the related model (B). Model A knows about Model B, but Model B has no knowledge of Model A. When using DB.AutoMigrate, GORM automatically creates the tables and the foreign key constraint on the model containing the ID field.
    type Dog struct {
    	ID        uint
    	Name      string
    	GirlGod   GirlGod // Association
    	GirlGodID uint     // Foreign Key
    }
    
    type GirlGod struct {
    	ID   uint
    	Name string
    }
  7. Understand Rollup's Build and Output phases

    Rollup's plugin lifecycle is divided into two primary stages:

    1. Build Phase: Focuses on resolving module content and dependency relationships. Hooks in this phase typically operate at the module level (single file), handling tasks like AST parsing and code transformation.
    2. Output Phase: Focuses on bundling and outputting the final files. Hooks in this phase typically operate at the chunk level (multiple files bundled together).
  8. Understand RabbitMQ Exchange basics

    An Exchange receives messages from a Producer and routes them to Queues based on specific rules defined by the exchange type. If the exchange name in ch.PublishWithContext is an empty string, RabbitMQ uses the default exchange, which routes messages directly to the queue named by the routing key.
    // Example of using the default exchange (empty string)
    err = ch.PublishWithContext(
        withTimeoutCtx,
        "",         // exchange name (empty = default)
        queue.Name, // routing key (acts as queue name here)
        false,      
        false,      
        amqp.Publishing{...},
    )
    
  9. Understand RabbitMQ core concepts

    RabbitMQ is a message broker that accepts and forwards messages. Key concepts include:

    • Message: The binary data block that RabbitMQ receives, stores, and forwards.
    • Producer: The user application that sends messages.
    • Exchange: Receives messages from producers and pushes them to queues based on specific rules (e.g., whether to add to a specific queue, multiple queues, or discard the message).
    • Queue: A buffer that stores messages.
    • Consumer: The user application that receives messages.
  10. Interpret Go benchmark test results

    When running Go benchmarks, the output provides several key metrics to evaluate performance:

    • goos and goarch: The operating system and CPU architecture of the machine running the test.
    • BenchmarkName-N: The name of the benchmark function and the number of CPU cores (N) used.
    • Total Iterations: The total number of times the benchmark function was executed (corresponding to b.N in the code).
    • ns/op: The average time taken for a single operation in nanoseconds.
    • B/op: The average amount of memory allocated per operation in bytes.
    • allocs/op: The average number of distinct memory allocations per operation.
  11. Understand the Vite plugin architecture

    Vite's plugin system is based on Rollup and extends the Rollup plugin interface. This allows a single plugin to work for both development (dev server) and production builds. During development, Vite simulates Rollup's behavior across three main phases: Server Start (options, buildStart), Request Response (resolveId, load, transform), and Server Close (buildEnd, closeBundle). Note that moduleParsed is skipped for performance, and most Output Generation hooks (except closeBundle) are not called during dev.