Missing Semester - Lecture 4

# journalctl run remotely, grep run locally ssh myserver journalctl | grep sshd # both commands run remotely ssh myserver "journalctl | grep sshd" sed sed (Stream Editor) is a powerful command-line tool in Unix/Linux that is used for parsing and transforming text, typically used for finding, replacing, or deleting content in a file or input stream. Common sed Commands: Substitution (s): sed 's/pattern/replacement/' file s: The substitution command. pattern: The string or pattern to search for. replacement: The string to replace the pattern with. Example: ...

October 15, 2024 · Last updated on August 1, 2025 · 7 min · KKKZOZ

Missing Semester - Lecture 2

Shell Scripting To assign variables in bash, use the syntax foo=bar and access the value of the variable with $foo. Note that foo = bar will not work since it is interpreted as calling the foo program with arguments = and bar. bash uses a variety of special variables to refer to arguments, error codes, and other relevant variables: $0 - Name of the script $1 to $9 - Arguments to the script. $1 is the first argument and so on. $@ - All the arguments $# - Number of arguments $? - Return code of the previous command $$ - Process identification number (PID) for the current script !! - Entire last command, including arguments. A common pattern is to execute a command only for it to fail due to missing permissions; you can quickly re-execute the command with sudo by doing sudo !! $_ - Last argument from the last command. If you are in an interactive shell, you can also quickly get this value by typing Esc followed by . or Alt+. Exit codes can be used to conditionally execute commands using && (and operator) and || (or operator). ...

October 11, 2024 · Last updated on August 1, 2025 · 5 min · KKKZOZ

Missing Semester - Lecture 1

The shell How does the shell know how to find the date or echo programs? The shell is a programming environment, just like Python, and so it has variables, conditionals, loops, and functions. If the shell is asked to execute a command that doesn’t match one of its programming keywords, it consults an environment variable called $PATH that lists which directories the shell should search for programs when it is given a command ...

October 9, 2024 · Last updated on August 1, 2025 · 2 min · KKKZOZ

Watchdogs in OpenFaaS

Classic Watchdog OpenFaaS 的 Classic Watchdog 是一个用于处理无服务器(Serverless)函数请求的核心组件。它是 OpenFaaS 的默认函数执行器,用于在容器内运行用户定义的函数代码,并通过 HTTP 请求与外部进行通信。 工作原理 Classic Watchdog 主要负责以下任务: 启动函数: 当容器启动时,Classic Watchdog 会启动并监听 HTTP 端口。 它会执行用户提供的函数代码,通过 exec 启动一个新的进程运行函数。 处理请求: Classic Watchdog 监听指定端口上的 HTTP 请求。 当收到请求时,它会将请求的内容传递给函数进程,并等待函数的响应。 返回响应: 函数进程处理请求后,将结果返回给 Classic Watchdog。 Classic Watchdog 将函数的响应封装成 HTTP 响应,并返回给调用方。 A tiny web-server or shim that forks your desired process for every incoming HTTP request Every function needs to embed this binary and use it as its ENTRYPOINT or CMD, in effect it is the init process for your container. Once your process is forked the watchdog passses in the HTTP request via stdin and reads a HTTP response via stdout. This means your process does not need to know anything about the web or HTTP. ...

August 25, 2024 · Last updated on August 1, 2025 · 7 min · KKKZOZ

A Piece Of: Logs

Log Levels Log levels for software applications have a rich history dating back to the 1980s. One of the earliest and most influential logging solutions for Unix systems, Syslog, introduced a range of severity levels, which provided the first standardized framework for categorizing log entries based on their impact or urgency. The following are the levels defined by Syslog in descending order of severity: Emergency (emerg): indicates that the system is unusable and requires immediate attention. Alert (alert): indicates that immediate action is necessary to resolve a critical issue. Critical (crit): signifies critical conditions in the program that demand intervention to prevent system failure. Error (error): indicates error conditions that impair some operation but are less severe than critical situations. Warning (warn): signifies potential issues that may lead to errors or unexpected behavior in the future if not addressed. Notice (notice): applies to normal but significant conditions that may require monitoring. Informational (info): includes messages that provide a record of the normal operation of the system. Debug (debug): intended for logging detailed information about the system for debugging purposes. The specific log levels available to you may defer depending on the programming language, logging framework, or service in use. However, in most cases, you can expect to encounter levels such as FATAL, ERROR, WARN, INFO, DEBUG, and TRACE. ...

May 13, 2024 · Last updated on August 1, 2025 · 5 min · KKKZOZ

Transaction Anomalies

Non-Repeatable Read A non-repeatable read occurs, when during the course of a transaction, a row is retrieved twice and the values within the row differ between reads. Phantom Read A phantom read occurs when, in the course of a transaction, two identical queries are executed, and the collection of rows returned by the second query is different from the first. Read Skew Read skew is that with two different queries, a transaction reads inconsistent data because between the 1st and 2nd queries, other transactions insert, update or delete data and commit. Finally, an inconsistent result is produced by the inconsistent data. ...

March 31, 2024 · Last updated on August 1, 2025 · 2 min · KKKZOZ

Programming Rust Book Note

Chapter 3 Types Arrays 不支持动态开数组: // an array of 100 int32 elements, all set to 1 let mut arr1 = [1;100]; // correct let n = 100; let mur arr2 = [1;c]; // error Vectors let mut arr = vec![0,6,4,8,1]; arr.sort() // increasing order arr.sort_by(|a,b| b.cmp(a)) // decreasing order If you know the number of elements a vector will need in advance, instead of Vec::new you can call Vec::with_capacity to create a vector with a buffer large enough to hold them all, right from the start. ...

February 10, 2024 · Last updated on August 1, 2025 · 46 min · KKKZOZ

A Piece Of: Go Tests

最近在写毕设项目时,总是发现有些单元测试在 VSCode 的 Testing Panel 连续运行测试时无法通过,但是单独运行时能正常通过,困扰了我好长一段时间。 有一次我发现了一个盲点: 在我写的框架中,有一个 config.go 文件: var Config = config{ LeaseTime: 1000 * time.Millisecond, MaxRecordLength: 2, IdGenerator: NewIncrementalGenerator(), Serializer: serializer.NewJSONSerializer(), LogLevel: zapcore.InfoLevel, } 当我从 Testing Panel 连续运行测试时,不同的测试都会复用 IdGenerator。 从网上查了资料后,才知道: The behavior you’re seeing is expected because Config is a global variable and it’s shared across the entire package. This means that state, such as the current ID from your NewIncrementalGenerator (), is preserved and reused across all your tests running within the same package. Go runs test functions (those starting with Test) in parallel by default, but within a single test package, they all share the same memory space. Therefore, global variables will persist their state across individual tests within that package. ...

January 21, 2024 · Last updated on August 1, 2025 · 1 min · KKKZOZ