Aimer-fan Technical Notes
website·Indexed 30 days ago
https://aimer-fan.github.io/A collection of technical notes and guides covering Bash scripting, web development (Vue, CSS, JavaScript, Qiankun), Nginx configuration, SQL operators, and various software deployment tutorials including Nextcloud and acme.sh.
What's inside Aimer-fan Notes
- A View is a virtual table that represents a logical display of data from one or more underlying tables (called base tables). Views do not store data themselves; they store a SELECT statement. Creating or deleting a view does not affect the base tables, but modifying data through a view typically affects the base tables. Views are particularly useful in large projects for simplifying complex queries, formatting data, and restricting user access to sensitive columns.
Overview of Bash Pattern Expansion (Globbing)
Bash performs pattern expansion (globbing) on tokens after splitting user input by spaces but before executing the command. This means the expansion is handled by the shell, and the command receives the final expanded arguments. Bash provides eight types of expansion: tilde,?,*,[], brace, variable, sub-command, and arithmetic expansion.Overview of MySQL Data Types
MySQL provides a wide variety of data types to handle different kinds of information. Key categories include:
- Integer Types: TINYINT, SMALLINT, MEDIUMINT, INT (or INTEGER), BIGINT
- Floating-Point Types: FLOAT, DOUBLE
- Fixed-Point Types: DECIMAL
- Bit Type: BIT
- Date and Time Types: YEAR, TIME, DATE, DATETIME, TIMESTAMP
- Text String Types: CHAR, VARCHAR, TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT
- Enum and Set Types: ENUM, SET
- Binary String Types: BINARY, VARBINARY, TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB
- JSON Type: JSON objects and arrays
- Spatial Data Types: GEOMETRY, POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION
Overview of SQL Data Integrity Constraints
SQL constraints are table-level rules used to ensure Data Integrity, which consists of four types:
- Entity Integrity: Prevents duplicate records that cannot be distinguished (e.g., Primary Keys).
- Domain Integrity: Restricts values to a specific range or format (e.g., age between 0-120).
- Referential Integrity: Ensures relationships between tables remain consistent (e.g., Foreign Keys).
- User-defined Integrity: Custom business rules (e.g., unique usernames).
Constraints can be defined as Column-level (defined immediately after the column) or Table-level (defined separately at the end of the table definition). Note that MySQL does not support the
CHECKconstraint (it can be written but has no effect).Overview of qiankun micro-frontend framework
qiankun is a micro-frontend solution based on single-spa. It allows a large monolithic application to be split into multiple independent sub-applications that can be developed and deployed separately. Key improvements over single-spa include the use of HTML entries instead of just JS entries, the provision of a runtime JS sandbox for isolation, and a simplified communication mechanism between applications.Use CSS Pre-processors for scalable styling
CSS Pre-processors like Less, Sass, Stylus, and PostCSS allow developers to use programming features such as variables, nesting, mixins, and inheritance. These files are compiled into standard CSS during the build process (e.g., via Webpack). While they improve maintainability, they may result in larger CSS bundles because they cannot easily track unused styles during compilation.#lib() { .colors() { @primary: blue; @secondary: green; } .rules(@size) { border: @size solid white; } } .box when (#lib.colors[@primary] = blue) { width: 100px; height: ($width / 2); } .bar:extend(.box) { @media (min-width: 600px) { width: 200px; #lib.rules(1px); } }Optimize Nginx worker processes and connection limits
Nginx uses a master-worker architecture with IO multiplexing. To maximize CPU performance and minimize context switching, the number of
worker_processesshould typically equal the number of CPU cores.Calculating Maximum Concurrent Connections:
- Total Max Connections:
worker_connections * worker_processes - Static Content (HTTP 1.1):
(worker_connections * worker_processes) / 2(since browsers often use two connections). - Reverse Proxy:
(worker_connections * worker_processes) / 4(since each request requires a connection to the client and a connection to the backend server).
# Set number of worker processes worker_processes 4; # Bind workers to specific CPUs (Example for 4 workers on 4 CPUs) worker_cpu_affinity 0001 0010 0100 1000; # Bind 4 workers to 4 specific CPUs out of 8 worker_cpu_affinity 00000001 00000010 00000100 00001000;- Total Max Connections:
Understand the role of a Shell in Linux
A Shell is a command-line interface (CLI) that acts as an intermediary between the user and the operating system kernel. It serves three primary roles: 1) A program providing a command-line environment for user interaction, 2) A command interpreter that supports variables, conditional logic, and loops for writing scripts, and 3) A toolbox providing utilities to access operating system functions.SQL Standards and Background
SQL (Structured Query Language) is a language used for data applications based on the relational model. Developed by IBM in the 1970s, it is standardized by the American National Standards Institute (ANSI). While various database vendors implement their own specific extensions, most modern SQL implementations follow the core standards, most notably SQL-92 and SQL-99.Understand JavaScript data storage in stack and heap
v8-gcJavaScript stores data in two primary locations based on the data type:
- Stack Memory: Stores primitive data types. These include Boolean, Null, Undefined, Number, String, Symbol (ES2015), and Bigint (ES2019). Primitive values are copied by value during assignment.
- Heap Memory: Stores all object data types. Objects are copied by reference (address) during assignment.
Understand MySQL single-row functions
Single-row functions in MySQL operate on each row of a result set independently, returning one value for every row processed. These are distinct from aggregate functions (group functions) which operate on sets of rows to return a single summary value. Note that SQL functions vary significantly between different DBMS (Database Management Systems); for example, while many use||or+for concatenation, MySQL uses theconcat()function. This makes function-heavy SQL code less portable across different database platforms.Understand the benefits and trade-offs of using SQL Views
SQL Views are virtual tables based on the result-set of an SQL statement. They provide several advantages for database architecture and security, but come with maintenance overhead.
Advantages:
- Simplified Operations: Developers can interact with a view without needing to understand the underlying table structures, complex join relationships, or business logic.
- Reduced Data Redundancy: Views store the query definition rather than the data itself, meaning they do not consume additional storage space for the result set.
- Enhanced Data Security: Views act as an isolation layer between the user and the base tables. Access can be restricted to specific views, preventing users from directly querying sensitive base tables.
- Flexibility for Changing Requirements: When base table structures change, views can often be updated to maintain a consistent interface for the application, reducing the need for widespread code changes.
- Decomposition of Complex Logic: Complex queries can be broken down into multiple smaller views, which can then be combined to achieve the final result.
Disadvantages and Caveats:
- Maintenance Overhead: If the structure of a base table changes, all dependent views must be updated.
- Complexity of Nested Views: Creating views based on other views (nested views) can significantly degrade readability and increase the risk of system bugs.
- Performance and Management: An excessive number of views in a project can increase the overall database maintenance cost.