Wider Blog

website·Indexed 29 days ago

https://wider.netlify.app/

A technical blog featuring guides and tutorials on web development and software engineering. Content includes extending Markdown syntax for Remark.js and Astro.js, implementing dark mode with React and Tailwind CSS, SQL introductory and advanced manuals, NVIDIA TensorRT for deep learning inference, and discussions on loop variables and closures in Go, JavaScript, C, and Python.

Tokens
18.3K
Snippets
72
Records
97
Agent score
74%

What's inside Wider

  1. Overview of NVIDIA TensorRT for Deep Learning Inference

    TensorRT is a high-performance engine developed by NVIDIA specifically for optimizing the inference speed and performance of deep neural network models. It achieves these performance gains through several key optimization techniques: layer fusion, mixed precision, and quantization.
  2. Overview of the remark.js Markdown processing pipeline

    remark is a plugin for unified.js that transforms Markdown text into HTML through a multi-stage pipeline. The process involves converting raw text into a Markdown Abstract Syntax Tree (MDAST), which is then converted to a Hypertext Abstract Syntax Tree (HAST) via remark-rehype before being serialized to HTML.

    Key components of the parsing process include:

    1. micromark: Parses Markdown syntax into a stream of tokens.
    2. mdast-util-from-markdown: Converts the token sequence into an MDAST.
    3. Extensions: Both micromark and mdast-util-from-markdown support custom extensions to implement new syntax.
    Input (file.md) 
      -> Tokenize (micromark + micromarkExtension)
      -> Token Stream (enter/exit events)
      -> Grow Syntax Tree (mdast-util-from-markdown + fromMarkdownExtension)
      -> Transform Tree (transform treeNode)
      -> Serialize (mdast-util-to-markdown + toMarkdownExtension)
      -> Output
  3. Understand SQL Language Categories (DDL, DML, DCL)

    SQL commands are categorized into three main groups based on their purpose:

    • DDL (Data Definition Language): Used to change the database structure, such as creating, altering, and deleting database objects.
    • DML (Data Manipulation Language): Used to retrieve, insert, and modify data. This is the most common group of SQL commands.
    • DCL (Data Control Language): Used to manage user permissions and access control.
  4. Supported markdown and content features

    The theme supports MDX and includes the following content features:

    • Typography styles and code highlighting.
    • Admonition components via markdown directives (supported in *.md files).
    • Emojis and math formulas via KaTeX.
    • Mermaid diagram syntax.
    • Table of Contents (ToC) for posts.
    • Integration with Giscus and Waline for comments.
    • Algolia DocSearch support.
    • Automatic generation of RSS feeds and sitemaps.
  5. Optimize Deep Learning Inference with NVIDIA TensorRT

    TensorRT is a high-performance deep learning inference engine by NVIDIA. It improves the inference speed and performance of deep neural networks through techniques such as layer fusion, mixed precision, and quantization.
  6. Technology stack used to build the wider.netlify.app blog

    The blog is a static site built using Astro, React, and TailwindCSS. The author chose Astro specifically because it provides a functional local content management system, eliminating the need to build a custom one from scratch.
  7. Manage MySQL databases and tables using basic SQL commands

    Perform fundamental database and table operations in MySQL using the following standard SQL commands:

    Database Operations:

    • Create a new database: CREATE DATABASE
    • Remove a database: DROP DATABASE
    • Rename a database: RENAME DATABASE
    • Select a database for use: USE
    • List available databases or statements: SHOW

    Table Operations:

    • Create a new table: CREATE TABLE
    • Modify existing table structure: ALTER TABLE (used for adding new fields, modifying field attributes, or deleting fields)
    • Remove a table: DROP TABLE
    • Empty all data from a table: TRUNCATE TABLE
    • Rename a table: RENAME TABLE
    -- Database examples
    CREATE DATABASE my_database;
    USE my_database;
    
    -- Table examples
    CREATE TABLE users (id INT, name VARCHAR(50));
    ALTER TABLE users ADD email VARCHAR(100);
    TRUNCATE TABLE users;
    DROP TABLE users;
  8. Optimize Deep Learning Inference with TensorRT

    TensorRT is an NVIDIA high-performance engine designed to optimize the inference speed and performance of deep neural networks. It achieves this through techniques such as layer fusion, mixed precision, and quantization. It is typically used for deploying PyTorch models to CUDA-enabled hardware.
  9. Reference MySQL string and date data types

    Overview of MySQL types for text, binary data, and temporal values.
    Strings:
    - CHAR(N): Fixed-length (0-255 bytes), space-padded.
    - VARCHAR(N): Variable-length (0-65536 bytes).
    - TEXT types: TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT (stored on disk).
    - BLOB types: TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB (binary data on disk).
    - SET(<list>): Multiple choice selection.
    - ENUM(<list>): Single choice selection.
    
    Dates:
    - DATE: yyyy-MM-dd
    - TIME: HH:mm
    - YEAR: yyyy
    - DATETIME: yyyy-MM-dd HH:mm
    - TIMESTAMP: yyyy-MM-dd HH:mm (can act as timestamp)
  10. Implement a custom Admonition plugin for Remark.js

    To add custom Admonition (callout) syntax to a Remark.js pipeline, you must extend both the tokenizer (micromark) and the AST transformer (mdast-util-from-markdown). The implementation involves defining a custom MDAST node type, mapping specific admonition types (e.g., note, info, tip, caution, danger) to CSS classes and icons, and transforming the resulting AST into HTML structures using hast-util-from-html.
    import type { Paragraph, Parent, Text, Content } from 'mdast';
    import type { Content as HastContent } from 'hast';
    import type { Handle, Extension as FromMarkdownExtension } from 'mdast-util-from-markdown';
    import { fromHtml } from 'hast-util-from-html';
    
    export interface Admonition extends Parent {
      type: 'admonition',
      name: string,
    };
    export interface admonitionHTML extends Parent {
      type: 'admonitionHTML',
    }
    
    declare module 'mdast' {
      interface BlockContentMap {
        admonitionHTML: admonitionHTML;
        admonition: Admonition;
      }
      interface ParagraphData {
        admonitionTitle?: boolean;
      }
    }
    
    const admonitionConfig: Record<string, { title: string, icon: string, class: string }> = {
      note: { title: '备注', icon: '<svg>...</svg>', class: 'admonition-note' },
      info: { title: '信息', icon: '...', class: 'admonition-info' },
      tip: { title: '提示', icon: '...', class: 'admonition-tip' },
      caution: { title: '注意', icon: '...', class: 'admonition-caution' },
      danger: { title: '危险', icon: '...', class: 'admonition-danger' },
    };
    
    // Helper to create HAST-like nodes within MDAST
    function h(tagName: string, properties: Record<string, any>, children?: (Content | undefined | null | false)[]): admonitionHTML {
      const filteredChildren = children?.filter((child): child is Content => child !== undefined && child !== null && child !== false) ?? [];
      return {
        type: 'admonitionHTML',
        data: { hName: tagName, hProperties: properties },
        children: filteredChildren,
      };
    }
    
    // Transforms HTML strings (like icons) into MDAST nodes
    function toMdast(node: HastContent) {
      if (node.type === 'text') return { type: 'text', value: node.value } as Text;
      if (node.type === 'element') {
        const mdastNode = { type: 'admonitionHTML', data: { hName: node.tagName, hProperties: node.properties }, children: [] } as admonitionHTML;
        node.children.map(toMdast).forEach((child) => { if (child) mdastNode.children.push(child); });
        return mdastNode;
      }
      return null;
    }
    
    function htmlTemplate(type: string, title?: string | Content, children?: (Content | undefined | null | false)[]) {
      const key = type in admonitionConfig ? type : 'note';
      const config = admonitionConfig[key];
      let titleNode = typeof title === 'string' ? { type: 'text', value: title } as Text : (title || { type: 'text', value: config.title } as Text);
      const iconNode = config.icon ? toMdast(fromHtml(config.icon, { space: 'svg', fragment: true }).children[0]) : null;
    
      return h('div', { class: 'my-4 rounded-lg px-4 py-2 ' + config.class }, [
        h('div', { class: 'flex items-center text-base font-bold' }, [iconNode, titleNode]),
        children && children.length > 0 && h('div', { class: 'mt-2 prose-compact text-sm' }, children)
      ]);
    }
    
    export const fromMarkdown = (): FromMarkdownExtension => {
      return {
        enter: {
          admonition: function(token) { this.enter<Admonition>({ type: 'admonition', name: '', children: [] }, token); },
          admonitionTitle: function(token) { this.enter<Paragraph>({ type: 'paragraph', data: { admonitionTitle: true }, children: [] }, token); },
        },
        exit: {
          admonition: function(token) {
            const node = this.exit(token) as Admonition;
            const titleNodeIndex = node.children.findIndex((child) => child.type === 'paragraph' && child.data?.admonitionTitle);
            const titleNode = titleNodeIndex >= 0 ? node.children.splice(titleNodeIndex, 1)[0] as Paragraph : undefined;
            if (titleNode) titleNode.data = { ...titleNode.data, hName: 'span' };
            const subtree = htmlTemplate(node.name, titleNode, node.children);
            if (subtree) Object.assign(node, subtree);
          },
          admonitionName: function(token) {
            const node = this.stack[this.stack.length - 1] as Admonition;
            if (node.type === 'admonition') node.name = this.sliceSerialize(token);
          },
          admonitionTitle: function(token) { this.exit(token); },
        }
      };
    };
  11. Install TensorRT on Windows

    To install TensorRT on Windows, use the Zip File Installation method. Ensure CUDA and cuDNN are installed first. Download the appropriate TensorRT zip package from the NVIDIA developer page.
    # 1. Extract zip to a directory, e.g., C:\Program Files\NVIDIA GPU Computing Toolkit\TensorRT\v8.x.x.x
    # 2. Add <install_path>/lib and <install_path>/bin to the system PATH environment variable
    # 3. Install the python wheel from the <install_path>/python directory:
    pip install tensorrt-8.x.x-cp3x-none-win_amd64.whl