Tiktok Basic Knowledge

Basic knowledge of computer

最近市场的就业还是非常的糟糕,偶尔会得到一些面试,但总是掺杂一些基础知识的考察,不只是单纯的算法题。下面主要是我自己收集到的一些问题,方便自己后面回顾。

使用sys添加新路径

1
2
3
4
5
import sys
newPath = "path/to/your/module"
sys.path.append(newPath)
for path in sys.path:
print(path)

what is interrput Reuqest?

Interrupts are an event that causes a program to stop and start executing another program.

most case the interrupts generate by hardware like keyboard, mouse, printer, hard drive etc.

but programm itself can also generate interrupts.

interrrupt includes hardware interrputs and software interrputs.

interrput主要分为三种:

  1. 硬件中断(Hardware Interrupts)

    打键盘

    当你按下键盘上的一个键时,键盘控制器会产生一个中断信号,通知CPU有一个按键事件需要处理。

  2. 软件中断(Software Interrupts)

    the INT instruction in X86

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    section .data
    msg db 'Hello, World!', 0x0A ; 要打印的字符串

    section .text
    global _start

    _start:

    # # 你按下打印按钮,助理暂停其他工作,开始打印文件。
    ; 请求操作系统打印字符串
    mov eax, 4 ; 系统调用号 (sys_write)
    mov ebx, 1 ; 文件描述符 (stdout)
    mov ecx, msg ; 字符串地址
    mov edx, 13 ; 字符串长度
    int 0x80 ; 触发软件中断

    # 你按下退出按钮,助理收到请求,帮助你结束一天的工作。
    ; 请求操作系统退出程序
    mov eax, 1 ; 系统调用号 (sys_exit)
    xor ebx, ebx ; 退出码 (0)
    int 0x80 ; 触发软件中断
  3. 异常中断(Exceptions)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    def divide(a, b):
    try:
    result = a / b
    print(f"The result is {result}")
    except ZeroDivisionError:
    print("Error: Cannot divide by zero!")
    finally:
    print("Execution completed.")

    # 正常情况
    divide(10, 2) # 输出: The result is 5.0, Execution completed.

    # 异常情况
    divide(10, 0) # 输出: Error: Cannot divide by zero!, Execution completed.

Http 和 Https 区别

http: hypertext transfer protocol

Https: hypertext transfer protocol secure

the difference beteween http and https

  1. data security

    HTTP: Data is transmitted in plain text, and anyone on the transmission path can read the data.

    HTTPS: The data is encrypted via SSL/TLS protocol to ensure that the data is secure during transmission.

  2. port

    HTTP: default port: 80

    HTTPS: default port: 443

How to insert index in mysql

1
CREATE INDEX index_name ON TABLE_NAME(column_name);

创建unique index eg:

1
CREATE UNIQUE INDEX idx_user_email ON users (email);

创建组合index eg:

1
CREATE INDEX index_name ON TABLE_NAME(column1, column2);
1
CREATE INDEX idx_user_name_email ON users (name, email);

删除Index

1
DROP INDEX  index_name ON TABLE_NAME;

Run the program in the background(后台运行程序)

nohup

1
nohup python test.py &

Nohup:程序不会因为挂起(终端关闭)而停止。

&: 程序在后台运行

& 英语发音 ampersand

存储log

1
nohup python your_script.py > output.log 2>&1 &

nohup 是 “no hang up” 的缩写。它的作用是让命令在终端关闭后继续运行。

当你使用 nohup 命令运行一个程序时,这个程序会忽略所有的挂起(HUP)信号,即使终端被关闭,程序也不会停止。

> 是输出重定向符号,用于将标准输出(stdout)重定向到指定的文件。

在这里,标准输出将被重定向到 output.log 文件中。

2>&1

2 代表标准错误(stderr)

1 代表标准输出(stdout)

2>&1 的意思是将标准错误重定向到标准输出。

这意味着标准输出和标准错误都会写入 output.log 文件中

查看文件和日志

1
ls -l output.log
1
cat output.log

查看进程和结束进程

1
ps aux | grep your_script.py
1
2
user     12345  0.0  0.1  123456  7890 ?        S    10:00   0:00 python your_script.py
user 12346 0.0 0.1 123456 7890 pts/0 S+ 10:00 0:00 grep --color=auto your_script.py

结束进程

1
kill 12345
1
kill -9 12345

当然也可以直接查看后台启动所有程序并结束

1
ps aux| grep nohup
1
kill <PID>

404 和 503

404 NOT FOUND:

用户访问了一个不存在的商店地址,发现这个地址上没有商店。

503 Service Unavailable

相当于用户访问了一个商店地址,发现商店因为装修或顾客太多而暂时关闭,但商店本身是存在的

RAG是什么

Retrieval-Augmented Generation

Retrieval

当用户提出问题时,系统会从Pre-built knowledge base或互联网中检索与该问题相关的文档或信息片段。

Augmented

The retrieved information will be used to enrich or enhance the input of the generated model.

Generation

使用生成模型(如 GPT-4)基于增强的输入来生成回答的过程。

Eg:

假设用户问了一个关于某个复杂科技主题的问题,比如“量子计算的基本原理是什么?”

步骤1:检索

系统首先会从知识库中检索与“量子计算”相关的文档。例如,找到一篇维基百科的文章或一篇学术论文,提取出关于量子计算基本原理的相关段落。

步骤2:增强

检索到的段落可能包含以下信息:

量子计算利用量子位(qubits)的叠加和纠缠性质进行计算。量子位可以同时表示0和1,从而使得量子计算在处理某些问题时比经典计算机更有效。

步骤3:生成

生成模型接收到增强后的输入,结合检索到的信息,生成回答:

量子计算的基本原理涉及量子位(qubits)的叠加和纠缠性质。量子位不同于经典计算位,它可以同时表示0和1,这种特性允许量子计算在处理某些复杂问题时比传统计算机更高效。

通过 RAG 模型,系统可以在没有预先编码特定答案的情况下,生成更准确和上下文相关的回答。这种方法尤其适用于回答复杂、开放式的问题。

1
量子计算的基本原理涉及量子位(qubits)的叠加和纠缠性质。量子位不同于经典计算位,它可以同时表示0和1,这种特性允许量子计算在处理某些复杂问题时比传统计算机更高效。

Why 非关系database 比 关系型 database更适合大数据

  1. scability

    NoSQLDatabases can be easily expanded horizontally.

    即通过Add more servers to spread data and loadbalance

  2. flexible data model

    NoSQL数据库允许存储具有不同结构的数据,不需要预定义模式(Schema)

  3. Performance

    针对特殊query进行优化。

    一家金融公司需要实时处理Large amounts of transaction data,以便及时Detect abnormal transactions.

    we can use redis(key-value database)

    for each transaction, we store a key-value paris

    1
    SET transaction:12345 "{'user_id': 1, 'amount': 100.50, 'status': 'completed'}"

    It’s hashtable structure,所我们可以快速 Retrieve 和 Update the transaction

    1
    HSET transaction:12345 status "completed"

    use pub-sub mechanism to send msg to different services

    比如说 对于 financial transaction system, 我们需要handle transaction data in real time to retrival abnormal transaction.

    当用户交易订单,我们需要系统立即处理,并且发现异常的时候,通知相关服务处理。

    当用户发起一笔交易时,系统首先处理交易(例如验证用户身份、检查账户余额等)。

    处理完成后,系统发布交易状态更新消息到交易频道。

    订阅者(如风险监控服务)接收到交易更新消息后,可以立即分析交易数据。

    如果检测到异常交易(例如金额异常大或短时间内频繁交易),可以触发报警或自动冻结相关账户。