Moonglade

Modern Markdown blogging with AI-powered localization and search.

Tag: daily

RSS

Using `readFile` as an example, how to implement it in Node.js

This article provides an in-depth analysis of the underlying implementation mechanisms of file reading operations in Node.js, with a focus on tracing the call chains of `fs.readFileSync` and `fs.readFile`. It points out that, whether synchronous or asynchronous, all operations ultimately converge on libuv's `uv_fs_read` function, with the execution mode distinguished by the presence or absence of a callback function. At the code level, it details how `FSReqCallback` and its base class `FSReqBase` encapsulate request state after entering the C++ layer from the JS layer, and how tasks are dispatched to the event loop through the `AsyncCall` and `Dispatch` mechanisms. For the asynchronous flow, it emphasizes how the `ReqWrap` template class adapts to the libuv interface, and how the `AfterInteger` callback function triggers the Promise's Resolve logic to return the result upon completion of the operation. Additionally, the article analyzes the details of permission checks and file descriptor management within the `open` function, revealing Node.js's meticulous considerations for platform compatibility and resource management at each level of abstraction. Finally, it summarizes legacy issues such as built-in module loading and asynchronous construction, aiming to help readers gain a deep understanding of Node.js's core architecture and design philosophy.

Views 187
2025 c++ daily javascript libuv nodejs source-code study v8

v8 build for Linux platform

This article documents the complete process of compiling V8 source code in an Ubuntu 24.04 environment and resolving linking issues. The author aims to obtain the V8 static library to research C++ and JS interoperation. However, the official documentation lacks explanations of the implicit relationships between build parameters, leading to two major challenges: first, the default linker reports an "unknown architecture" error; second, V8's custom C++ standard library results in undefined symbols. After extensive trial and error, it was found that using the lld linker resolves the architecture compatibility issue. Furthermore, setting `is_clang` to `false` and `use_custom_libcxx` to `false` in `args.gn`, combined with `v8_monolithic=true`, ultimately resulted in the successful generation of a static library that links and debugs correctly. The article reflects on the insufficient guidance in V8's official documentation regarding critical build configurations and suggests that maintainers improve parameter documentation to reduce developers' trial-and-error costs, ensuring that documentation serves as a guide rather than an obstacle.

Views 289
2025 c++ daily linux study v8

Post-Mortem After a Drinking Session

This article is a profound reflection on the act of drinking alcohol, aimed at eliminating future violations of precepts through introspection. Based on the Buddhist principle of the Four Right Efforts, the author points out that although drinking is a minor precept (a restriction rather than a fundamental prohibition), it should be completely avoided to ensure absolute safety. The text details the experience of breaking the precept during the New Year period due to friends' forceful invitations and pressure to drink, and deeply analyzes the harms of such social scenarios: not only does it violate the precepts, but true friendship is not sustained by alcohol and meat; rather, the secular habits commonly accepted by the group often conflict with the goals of spiritual practice. The author emphasizes that when facing pressure from others, one must steadfastly adhere to the Dharma-based decision, without compromising or settling for a lesser standard due to the lack of a suitable environment or the persuasion of others—just as one should not compromise by eating the "Three Pure Meats" when vegetarian options are unavailable. This lesson can be extended to all unwholesome practices, reminding practitioners to maintain sharp awareness in daily life, hold firmly to the precepts, and let the Dharma guide their actions, thereby ensuring that wholesome qualities already present grow stronger and new wholesome qualities arise, thus truly fulfilling the goal of abandoning evil and cultivating goodness in practice.

Views 268
alcohol buddhist-precepts daily four-right-efforts foxue interpersonal-relationships mindfulness reflections study

Some Thoughts on Document Editing and Version Tracking

This article explores how to integrate Feishu Cloud Documents with Git version control to address the lack of fine-grained change tracking inherent in purely online documents during collaborative editing. The author points out that although Feishu supports version history, it lacks the critical feature of change descriptions, making it difficult to precisely locate historical versions during frequent revisions. In contrast, the Markdown format, due to its plain-text nature, is better suited for content-level version control via Git, effectively addressing needs such as content proofreading, multi-branch directory management, and low-cost web publishing. The article proposes a hybrid workflow: converting raw Word documents into unformatted Markdown and storing them in a Git repository as the source of truth for content version control; simultaneously importing the content into Feishu Cloud Documents for multi-user online commenting, discussion, and change approval. The Git branching mechanism allows for flexible management of different directory structures, while static site frameworks enable the easy conversion of Markdown into web pages or publication styles. This solution achieves a separation of content and formatting, ensuring both transparency and traceability in the revision process while meeting collaboration and publishing requirements across various scenarios. It serves as an effective strategy for handling complex document revision tasks.

Views 287
daily document-collaboration git markdown project-management static-site-generator version-control

NestJS pg template

This article introduces a backend project template based on NestJS, PostgreSQL, and TypeORM, aimed at providing a standardized development foundation. The article first outlines the configuration management approach, which involves reading YAML files and combining them with class-validator for strict data validation and transformation, ensuring the security and standardization of configurations. Next, it demonstrates how to use Docker Compose to quickly deploy Redis and PostgreSQL, optimizing the local development environment. The core functional modules include implementing database operations and migration management using TypeORM, as well as building a user authentication and permission control system based on JWT, Passport, and RBAC mechanisms, supporting dynamic retrieval of interface permission information via metadata. Additionally, the template integrates OpenAPI documentation generation and SDK automation tools to facilitate frontend integration. The logging system utilizes Winston and Dayjs to achieve Nest-style logging in development environments and file-based logging in production environments. Finally, the article covers specific data migration commands and a code submission process that follows the Conventional Commits specification, providing a complete technology stack reference for building robust, scalable enterprise-level backend applications.

Views 143
2024 daily nest node pgsql typeorm

GitLab Pipeline DingTalk Notification

This document describes how to integrate DingTalk bot notifications into a GitLab CI pipeline. The author created a base repository, `share/gitlab-ci`, which contains a `dingtalk.yml` template file. This file leverages GitLab Hook events to call the DingTalk API via `curl` to send messages. The core implementation includes defining global variables, validating the Access Token and URL-encoding the project address in the prepare stage, and constructing a Markdown message in the send stage that includes details such as task status, commit information, and the executor. It supports displaying different colors based on statuses like success or failure and includes jump buttons to view project and task details. In specific projects, this template is referenced using the `include` directive, and the `.dingtalk` configuration is inherited via `extends` in tasks across various stages, thereby enabling automated notifications for steps such as code inspection, building, and deployment. This solution addresses the previous issue where only repository information was recorded without pipeline notifications, achieving full-process visual feedback from task initiation to execution results. This enhances the transparency and collaboration efficiency of the DevOps workflow.

Views 342
ci-cd daily devops dingtalk integration gitlab gitlab ci

ts strict mode configuration, comfortable

This article primarily demonstrates the TypeScript compiler options configured in strict mode and highlights their positive impact on the development experience. The core configuration includes setting the module system to NodeNext, targeting ES2021 as the compilation target, and enabling strict mode to catch more potential errors. Additionally, to support modern frontend framework features, the configuration enables experimental decorators and decorator metadata emission, and generates declaration files and source maps for debugging purposes. Notably, to reduce type error friction during initialization, the configuration specifically disables strictPropertyInitialization, allowing properties to be initialized later in the constructor. The author concludes by expressing appreciation for the comfort brought by strict mode, indicating that through reasonable compiler option configuration, developers can enjoy the safety and maintainability of strict type checking while balancing development efficiency by fine-tuning certain rules, thereby achieving a smoother coding experience.

Views 185
config daily study ts typescript typescript compiler

pyenv Notes

This article documents the practice and experience of managing Python versions using `pyenv` in an Ubuntu 24.04 environment. The motivation was that while building the MongoDB source code, the official documentation required Python 3.10+, but the system's default version 3.12.3 caused the build to fail due to API incompatibility. Since modifying the source code was not an option, the decision was made to use `pyenv` to specifically install a 3.10.x version. The article details the process of automatically installing `pyenv` via a `curl` script and configuring `~/.bashrc`. It also highlights the extremely unfriendly user experience of `pyenv`, specifically noting the lack of progress indicators, minimal information feedback, and the absence of interactive options during installation and build processes. Additionally, addressing the issue where `pip` and `poetry` command-line mirror source configurations failed, the author successfully configured the Tsinghua University or Tencent Cloud mirror addresses to accelerate dependency package downloads by manually creating and editing the `~/.pip/pip.conf` and `~/.config/pypoetry/config.toml` files. The article emphasizes the importance of not arbitrarily modifying the system's pre-installed Python environment and repeatedly warns developers to avoid writing programs that lack user feedback and interactivity. It suggests that readers refer to this configuration method in similar scenarios to avoid potential pitfalls.

Views 97
daily env install mongodb pyenv study

debug vue3 source code

This article introduces a simple solution for implementing source code debugging in Vue 3 projects. The core idea is to leverage the sourcemap files generated during the Vue 3 build process, combined with VS Code debugging configuration, allowing direct execution without modifying complex configurations. The article first demonstrates how to install dependencies using `pnpm` and run the development command, resulting in build artifacts in the `dist` directory that include map files. It then provides detailed `launch.json` configuration examples covering three debugging scenarios: first, Node.js debugging for the `npm run build` script; second, debugging remotely loaded Vue projects via URL, where it is important to set `webRoot`; and third, debugging original HTML files that reference local Vue packages, requiring correct configuration of `outFiles` to map source code paths. The article also lists complete environment setup steps, including cloning the Vue core repository, creating temporary HTML test files, and creating a Vue project using the official template. This solution aims to help developers quickly establish a debugging chain from browser breakpoints to Vue source code, improving development efficiency. Plans are in place to supplement this with a debugging video demonstration in the future.

Views 60
daily sourcemap study vue vue3 web

Detailed records of pre-installed Ubuntu applications are documented here.

This document records the checklist of essential software to be installed on the Ubuntu 24.04 system and the operational details. The author lists commonly used software including v2raya proxy tool, Edge browser, VSCode-Insider, QQ, Git, curl, nvm, Docker, CopyQ, DBeaver, MongoDB Compass, VLC, OBS Studio, Four-Leaf Clover Pinyin Input Method, Calibre, Bing Wall, and uLauncher. The text specifically notes potential startup delays after installing the Edge browser, as well as possible permission insufficiency issues when installing curl via snap that may lead to Node.js download failures, and provides corresponding resolution ideas. Additionally, the article includes specific installation commands covering various methods such as snap, apt, flatpak, and script-based installation. Examples include using snap to install v2raya and VLC, using apt to install Git and flatpak, using scripts to install nvm, and using flatpak to install OBS and Calibre, providing a reference for subsequent supplementary software installations.

Views 228
2024 Development Tools Software Installation Ubuntu 24.04 daily ubuntu