Skip to content

Commit

Permalink
feat: add pre-commit (typos, check-yaml, end-of-file-fixer, trailing-…
Browse files Browse the repository at this point in the history
…whitespace) (#72)

* feat: add pre-commit (typos, check-yaml, end-of-file-fixer, trailing-whitespace)

* README: remove WIP

* - Fix End of Files
- Trim Trailing Whitespace
  • Loading branch information
Oreoxmt authored Sep 8, 2024
1 parent d62caf2 commit 65bb653
Show file tree
Hide file tree
Showing 25 changed files with 133 additions and 102 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/[email protected]
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- repo: https://github.com/crate-ci/typos
rev: v1.24.5
hooks:
- id: typos
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# WIP: oreo.life-v2
Use Docusaurus to build oreo.life
# oreo.life-v2

Use Docusaurus to build [oreo.life](https://oreo.life).
5 changes: 5 additions & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[default]


[default.extend-identifiers]
levlSkipRequest = "levlSkipRequest"
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ for name in os.listdir():

通过前面的一系列折腾终于完成了一键下载+批量改名,在下载的文件数量较多时,还可以采用并行的方法,提高效率。

关于并行部分的内容或许会在下次更新。
关于并行部分的内容或许会在下次更新。
2 changes: 1 addition & 1 deletion website/blog/2022-07-31-reading-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ I usually type some commands frequently and use ↑ to find commands. The articl
- To resolve a domain, use `dig` instead of `nslookup`.
- To display network connections, use `ss` instead of `netstat`.
- To get the network interface configuration, use `ip` instead of `ifconfig`.
- To manipulate entries in the kernel routing tables , use `ip route` instead of `route`.
- To manipulate entries in the kernel routing tables , use `ip route` instead of `route`.
14 changes: 7 additions & 7 deletions website/blog/2023-09-04-cpp-beginner-cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ make # This will execute the build files and build the project
Merge: e5b1c472 20d0c586
Author: Oreo
Date: Mon Sep 4 21:37:57 2023 +0800

Merge commit '20d0c58622d07bf66f125efff52cc440b88fe2eb' as 'thirdparty/fmt'

commit 20d0c58622d07bf66f125efff52cc440b88fe2eb
Author: Oreo
Date: Mon Sep 4 21:37:57 2023 +0800

Squashed 'thirdparty/fmt/' content from commit e8259c52

git-subtree-dir: thirdparty/fmt
git-subtree-split: e8259c5298513e8cdbff05ce01c46c684fe758d8
```
Expand Down Expand Up @@ -146,15 +146,15 @@ make # This will execute the build files and build the project
Receiving objects: 100% (32886/32886), 14.09 MiB | 23.39 MiB/s, done.
Resolving deltas: 100% (22295/22295), done.
```

查看 `git status`

```bash
git status
On branch main

No commits yet

Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: .gitmodules
Expand Down
30 changes: 15 additions & 15 deletions website/blog/2024-01-12-cpp-beginner-stringtoint-stringstream.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ To extract the price and unit from the string stream `iss`, use the following co

<Tabs>
<TabItem value="extract-price-double-code" label="Extract price (double) and unit">

```cpp
#include <iostream>
#include <sstream>

int main() {
std::istringstream iss("9.15 pounds.");
std::ostringstream oss("The price of the shirt is ");
Expand All @@ -72,7 +72,7 @@ To extract the price and unit from the string stream `iss`, use the following co
</TabItem>
<TabItem value="extract-price-double-output" label="Output">
```text
The price of the shirt is 9.15 pounds.
```
Expand All @@ -84,11 +84,11 @@ What is the behavior of `iss >> price >> unit`? We can modify the type of `price

<Tabs>
<TabItem value="extract-price-int-code" label="Extract price (int) and unit">

```cpp
#include <iostream>
#include <sstream>

int main() {
std::istringstream iss("9.15 pounds.");
std::ostringstream oss("The price of the shirt is ");
Expand All @@ -104,7 +104,7 @@ What is the behavior of `iss >> price >> unit`? We can modify the type of `price
</TabItem>
<TabItem value="extract-price-int-output" label="Output">
```text
The price of the shirt is 9 .15
```
Expand All @@ -120,18 +120,18 @@ Now, we can use `>>` to extract an integer from a string. Let's implement a func

<Tabs>
<TabItem value="string-to-int-first" label="Extract an integer from a string">

```cpp name="stringToInteger.cpp"
#include <iostream>
#include <sstream>

int stringToInteger(const std::string& str) {
std::istringstream iss(str);
int value;
iss >> value;
return value;
}

int main() {
std::string str = "123";
int value = stringToInteger(str);
Expand All @@ -143,7 +143,7 @@ Now, we can use `>>` to extract an integer from a string. Let's implement a func
</TabItem>
<TabItem value="string-to-int-first-output" label="Output">
```text
The value is: 123
```
Expand All @@ -166,12 +166,12 @@ To check the stream state, we can use the `good()`, `eof()`, `fail()`, and `bad(

<Tabs>
<TabItem value="stream-state-code" label="Check stream state">

```cpp
#include <iostream>
#include <sstream>
#include <vector>

void get_stream_state(std::istringstream &iss) {
if (iss.good()) {
std::cout << "G";
Expand All @@ -187,7 +187,7 @@ To check the stream state, we can use the `good()`, `eof()`, `fail()`, and `bad(
}
std::cout << std::endl;
}

int stringToInteger(const std::string &str) {
std::istringstream iss(str);
std::cout << "Before: ";
Expand All @@ -198,7 +198,7 @@ To check the stream state, we can use the `good()`, `eof()`, `fail()`, and `bad(
get_stream_state(iss);
return value;
}

int main() {
std::vector<std::string> test_strings{"123", "123abc", "abc123", ""};
for (const auto &str : test_strings) {
Expand All @@ -212,7 +212,7 @@ To check the stream state, we can use the `good()`, `eof()`, `fail()`, and `bad(
</TabItem>
<TabItem value="stream-state-output" label="Output">
```text
stringToInteger("123"):
Before: G
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,31 @@ Code example: [commit/10a7107](https://github.com/Oreoxmt/writerside-feedback-ex

```yaml title=".github/workflows/deploy.yml"
name: Build documentation

on:
push:
branches: ["main"]
workflow_dispatch:

env:
INSTANCE: writerside-feedback/hi
ARTIFACT: webHelpHI2-all.zip
DOCKER_VERSION: 233.14272

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build Writerside docs using Docker
uses: JetBrains/writerside-github-action@v4
with:
instance: ${{ env.INSTANCE }}
artifact: ${{ env.ARTIFACT }}
docker-version: ${{ env.DOCKER_VERSION }}

- name: Upload documentation
uses: actions/upload-artifact@v4
with:
Expand All @@ -75,7 +75,7 @@ Code example: [commit/10a7107](https://github.com/Oreoxmt/writerside-feedback-ex
artifacts/${{ env.ARTIFACT }}
artifacts/report.json
retention-days: 7

deploy:
needs: build
runs-on: ubuntu-latest
Expand Down Expand Up @@ -174,12 +174,12 @@ Therefore, it is necessary to have a server in place to receive this request and
## 3. Configure TiDB Cloud Data Service for feedback storage

1. [Create a TiDB Serverless cluster](https://docs.pingcap.com/tidbcloud/create-tidb-cluster-serverless) and initialize the database as follows. For convenience, you can use [Chat2Query](https://docs.pingcap.com/tidbcloud/explore-data-with-chat2query) in the TiDB Cloud console.

```sql
CREATE DATABASE demo;
USE demo;
CREATE TABLE
feedback (
id INT PRIMARY KEY AUTO_INCREMENT,
Expand All @@ -203,7 +203,7 @@ Therefore, it is necessary to have a server in place to receive this request and
- Set the **Path**, for example, `/feedback`.
- Select **POST** as the **Request Method**.
- Input the following SQL statements into the editor:

```sql
USE demo;
INSERT INTO feedback (
Expand All @@ -215,7 +215,7 @@ Therefore, it is necessary to have a server in place to receive this request and
```

- Configure the parameters as follows:

| Parameter | Type | Description |
|-----------|--------|--------------------------|
| articleId | String | The article ID. |
Expand Down Expand Up @@ -271,7 +271,7 @@ Code example: https://github.com/Oreoxmt/writerside-feedback-example/commit/dd61
This function forwards the feedback request to TiDB Cloud Data Service, which is configured in the `API_HOST` and `API_AUTH` environment variables.

2. Incorporate the *Add function folder to output file* step in the `deploy.yml` workflow. After building the documentation, this step adds the `functions` folder to the output file, facilitating the deployment of the function to Cloudflare Pages.

```yaml title=".github/workflows/deploy.yml"
name: Build documentation
Expand Down
2 changes: 1 addition & 1 deletion website/blog/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ Tips & Tricks:
Writerside:
label: 'Writerside'
description: 'Blog posts related to Writerside'
permalink: /writerside
permalink: /writerside
18 changes: 9 additions & 9 deletions website/docs/cpp/cpp-wiki.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The following code examples show the difference between using `std::endl` and no

```cpp
#include <iostream>

int main() {
for (int i = 0; i < 5; i++) {
std::cout << i << std::endl;
Expand All @@ -74,7 +74,7 @@ The following code examples show the difference between using `std::endl` and no
```cpp
#include <iostream>
int main() {
for (int i = 0; i < 5; i++) {
std::cout << i; // 01234
Expand Down Expand Up @@ -107,9 +107,9 @@ The following code examples show the same output with `std::endl` and `\n` in st

```cpp name="std_endl.cpp"
#include <unistd.h>

#include <iostream>

int main() {
for (int i = 0; i < 5; i++) {
sleep(1);
Expand All @@ -133,9 +133,9 @@ The following code examples show the same output with `std::endl` and `\n` in st
```cpp name="new_line_character.cpp"
#include <unistd.h>
#include <iostream>
int main() {
for (int i = 0; i < 5; i++) {
sleep(1);
Expand Down Expand Up @@ -204,7 +204,7 @@ The following example shows the duration for printing 100,000 numbers with `std:
```cpp
#include <chrono> // for timers
#include <iostream> // for cin, cout

int endl_each_time(int n = 10000) {
const auto start_time = std::chrono::steady_clock::now();
for (int i = 0; i < n; i++) {
Expand All @@ -215,7 +215,7 @@ The following example shows the duration for printing 100,000 numbers with `std:
end_time - start_time);
return duration_ns.count();
}

int new_line_each_time(int n = 10000) {
const auto start_time = std::chrono::steady_clock::now();
for (int i = 0; i < n; i++) {
Expand All @@ -227,7 +227,7 @@ The following example shows the duration for printing 100,000 numbers with `std:
start_time);
return duration_ns.count();
}

int main() {
int endl_duration = endl_each_time();
int new_line_duration = new_line_each_time();
Expand Down
Loading

0 comments on commit 65bb653

Please sign in to comment.