Live Note

Remain optimistic

在 TypeScript 的类型系统中,逆变(Contravariance)协变(Covariance)双变(Bivariance)不变(Invariance) 是描述类型兼容性和子类型关系的重要概念。这些术语来源于类型理论,主要用于处理函数类型、泛型和接口的赋值规则。理解这些概念不仅能帮助我们编写更安全的代码,还能让我们更好地设计类型系统。本文将逐一讲解这四种变型,辅以代码示例,让你轻松掌握它们的含义与应用。

Read more »

基本类型

  • boolean:
    1
    let done: boolean = true
  • number:
    1
    let count: number = 20
  • string:
    1
    let name = "Edward Wang"
  • array:
    1
    2
    let list1: number[] = [1, 2, 3]
    let list2: Array<number> = [1, 2, 3]
  • tuple:
    1
    let x: [string, number] = ["test", 2]
  • enum:
    1
    2
    3
    4
    5
    6
    7
    enum NUMBER {
    ONE,
    TWO,
    THREE,
    }
    let a = NUMBER.TWO
    let title: string = NUMBER[3]
Read more »

1
2
3
4
5
6
7
8
9
10
const enum Foo {
AA = "aa",
BB = "bb",
}

type B = keyof typeof Foo // 'AA' | 'BB'

// Template Literal Types
type C = `${keyof { [x in Foo]: string }}`
// 'aa' | 'bb'

缘由

公司的 PC 没有音卡。导致耳机不能播放。

使用 pavucontrol 输出为模拟信号

刚开始总报找不到这个 package。
换了官方源也没用。
后来才发现需要打开开源 package 安装。。。software & updates > ubuntu software > open-source software

Node.js is built on Google’s V8 engine, and V8’s garbage collection mechanism is one of its core performance features. In this article, we’ll explore the three primary garbage collection algorithms used in V8: Mark-Sweep, Mark-Compact, and Scavenge, along with their working principles and application scenarios.

V8’s Memory Partition Model

Before diving into garbage collection algorithms, we need to understand V8’s memory partition model. V8 divides memory into two main regions:

Young Generation

  • Contains objects with short lifespans.
  • Typically small in size (e.g., a few MB).
  • Uses the Scavenge algorithm for garbage collection.

Old Generation

  • Contains objects with longer lifespans.
  • Typically larger in size (e.g., hundreds of MB).
  • Uses the Mark-Sweep and Mark-Compact algorithms for garbage collection.
Read more »