aboutsummaryrefslogtreecommitdiff
path: root/docs/applications/programming
diff options
context:
space:
mode:
Diffstat (limited to 'docs/applications/programming')
-rw-r--r--docs/applications/programming/cpp.md167
-rw-r--r--docs/applications/programming/miniconda.md84
-rw-r--r--docs/applications/programming/python.md93
3 files changed, 344 insertions, 0 deletions
diff --git a/docs/applications/programming/cpp.md b/docs/applications/programming/cpp.md
new file mode 100644
index 0000000..e5d01b7
--- /dev/null
+++ b/docs/applications/programming/cpp.md
@@ -0,0 +1,167 @@
+# C++
+
+## Windows 的配置灾难
+
+众所周知,在windows上安装VSCode并配置好mingw编译器对于很多新手来说都是一件非常曲折的事情。
+因为 Windows 的主要受众是普通人,所以软件管理,编译器配置方面都不如Linux便利。
+
+如果你选择了 Linux ,那么恭喜你将获得一个非常便利而自然的开发环境。
+接下来我简单介绍一下如何在 Linux 上跑通一个 简单的 Hello World 以及多文件编译。
+
+## g++ 安装
+
+g++ 编译器是专门用于编译 cpp 代码的(也就是让你写的东西能用机器跑起来)。
+安装非常简单,取决于你使用什么包管理器。
+
+- Debian 系(Ubuntu, Mint, Debian)
+
+```bash
+sudo apt install g++ -y
+```
+
+- 红帽系(Fedora, rhel, rocky)
+
+```bash
+sudo dnf install g++ -y
+```
+
+- Arch系
+
+```bash
+sudo pacman -S g++ -y
+```
+
+- 查看版本
+
+```bash
+g++ -v
+```
+
+参考输出:
+❯ g++ -v
+
+```shell
+Using built-in specs.
+COLLECT_GCC=g++
+COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/16/lto-wrapper
+Target: x86_64-pc-linux-gnu
+Configured with: ../gcc/configure --enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust,cobol --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodi
+r=/usr/share/info --with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues --with-build-config=bootstrap-lto --with-gcc-major-version-only --with-linker-hash-style=gnu --with-system-zl
+ib --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-libstdcxx-backtrace --enable-link-s
+erialization=1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-fixincludes --disable-libssp --disable-libstdcxx-pch --disable-werror
+Thread model: posix
+Supported LTO compression algorithms: zlib zstd
+gcc version 16.1.1 20260725 (GCC)
+```
+
+
+## 编写一个程序
+
+- 创建一个cpp文件(以cpp为后缀)
+
+```bash
+touch hello.cpp
+```
+
+- 使用你喜欢的编辑器打开
+
+```bash
+vim hello.cpp
+# 如果你不会用 vim 就用nano
+# nano hello.cpp
+```
+
+- 写入下面的内容
+
+```cpp
+#include <iostream>
+
+int main() {
+ std::cout << "hello world" << std::endl;
+ return 0;
+}
+```
+
+- 保存并退出
+
+- 编译成二进制文件
+
+```bash
+g++ hello.cpp -o hello
+```
+
+> -o <file> Place the output into <file>.
+这里 -o 表示 output(输出的二进制文件), 后面跟上你起的二进制文件名, 随便叫啥,一般会叫main或者你的程序名。
+
+写法是 g++ 源文件路径 -o 二进制文件。
+
+- 运行程序
+
+```bash
+./hello # ./ 表示当前目录, 后面直接跟上文件名, 表示运行该二进制文件
+```
+
+这个时候终端会打印 hello world, 恭喜你成功用命令行成功编写并运行了一个C++程序。
+
+## 多文件编译
+
+当我们的源文件不止一个的时候, 我们需要在编译的时候把所有用到的源文件都写上(当然仅限于自己写的那些源文件,标准库就不需要了)。
+
+比如说这个项目:
+
+```bash
+❯ tree
+.
+├── CMakeLists.txt
+├── compile_commands.json
+├── include
+│   ├── legacy
+│   │   ├── CommentIO.hpp
+│   │   ├── Filter.hpp
+│   │   ├── LegacyFilterPipeline.hpp
+│   │   └── NaiveScanner.hpp
+│   ├── lib
+│   │   ├── csv.hpp
+│   │   └── simdutf.h
+│   └── localLib
+│   ├── BloomDeduplicator.hpp
+│   ├── Comment.hpp
+│   ├── CommentInteractiveInput.hpp
+│   ├── CsvCommentInput.hpp
+│   ├── CsvUtil.hpp
+│   ├── Deduplicator.hpp
+│   ├── FilterPipeline.hpp
+│   ├── HammingDeduplicator.hpp
+│   ├── ICommentSource.hpp
+│   ├── Matrix.hpp
+│   ├── mini_test.h
+│   ├── PathUtil.hpp
+│   ├── Recorder.hpp
+│   ├── SlidingWindowLimiter.hpp
+│   ├── Trie.hpp
+│   ├── WatchMode.hpp
+│   ├── WordAppender.hpp
+│   ├── WordLibarary.hpp
+│   └── WorkPerformaceAnalyser.hpp
+├── makefile
+├── src
+│   ├── main.cpp
+│   └── simdutf.cpp
+```
+
+不要看有这么多文件, 但是这个明显是一个 header only 的项目, 只有 src/ 目录里面有两个cpp 文件,所以我们只需要编译的时候指定这两个即可。
+
+```bash
+# 创建一个 bin 目录放产物 如果你还没有的话
+mkdir -p bin
+
+g++ src/simdutf.cpp src/main.cpp -o bin/main
+# 当然我们有更好的策略, 我们使用的可是高贵的Linux
+# g++ src/* -o bin/main
+# 直接使用通配符编译所有的cpp文件
+```
+
+这里给个建议就是将cpp源文件和hpp头文件分开,这样方便管理。
+
+现在你已经学会如何使用命令行编译cpp程序了,当然还有各种的编译方式,有各种编译工具,但是入门的话现在这些知识就够了。
+祝贺你。
diff --git a/docs/applications/programming/miniconda.md b/docs/applications/programming/miniconda.md
new file mode 100644
index 0000000..cd445af
--- /dev/null
+++ b/docs/applications/programming/miniconda.md
@@ -0,0 +1,84 @@
+# Miniconda
+
+## 什么是Miniconda
+
+相信不少人是因为自己需要学习人工智能,跑云端训练才学Linux
+所以我在这里写了相关的内容,希望可以帮助到大家。
+
+Anaconda 是一个 **Python的管理器**,让你在同一个操作系统上**拥有多个共存的Python环境,按需使用和激活**。
+但是 Anaconda 预装太多东西,甚至达到几个G的体积,所以官方也推出了mini版 —— Miniconda。
+
+Miniconda 跟Anaconda的最大区别就是砍掉了很多预装的东西,比如numpy之类的。
+它的设计理念就是让用户按需安装,我是比较同意这个理念的,个人也一直在用Miniconda。
+
+**下面的教程适用于Linux环境(包括原生Linux,WSL,虚拟机等)**
+
+## 安装步骤
+
+- 下载官方安装脚本
+访问官方下载链接(https://www.anaconda.com/download/success)
+
+选择 Linux,选择右边这个 Miniconda x86 版本 (大多数电脑都是x86, 但是macBook不是,在这之前确认自己的架构)。
+
+![Anaconda安装脚本下载](../../img/miniconda/pic1.png)
+
+- 使用bash执行脚本
+
+```bash
+# 首先需要把你的 Miniconda脚本放到Linux系统可以访问的地方
+
+# 然后执行这个安装脚本
+bash Miniconda3-latest-Linux-x86_64.sh
+```
+
+然后中间有引导,保持默认即可,叫你输yes你就yes回车。安装完之后重启终端或者使用下面的命令重新加载环境变量。
+
+```bash
+source ~/.bashrc
+```
+
+- 配置镜像源
+
+很多同志连官方源不太流畅,推荐换成清华镜像源。
+
+访问这个链接进行配置即可:https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/
+
+一般是创建一个 ~/.condarc 文件然后把 channels 开头的那些东西复制粘贴进去即可。
+
+```bash
+# 创建配置文件
+touch ~/.condarc
+# 然后编辑
+nano ~/.condarc
+```
+
+- 配置pip源
+
+我们很多时候还是使用 pip 来安装的,所以这里也需要配置一下pip的镜像源
+
+访问这个网址进行配置 https://mirrors.tuna.tsinghua.edu.cn/help/pypi/
+**只需要执行设为默认的命令即可**, 剩下的不需要配置。
+
+- 创建环境测试
+
+```bash
+# 这边的 -n 后面的是虚拟环境名, 这里既是 test-env. 然后后面可以指定python版本,根据实验需要来
+conda create -n test-env python=3.12
+```
+
+- pip安装测试
+
+```bash
+# 先激活刚才创建的虚拟环境
+conda activate test-env
+
+# 然后装个 numpy 试试
+pip install numpy
+```
+
+- 查看当前环境
+
+```bash
+conda env list
+# 列出所有环境, 如果是当前的环境, 会标有 *
+```
diff --git a/docs/applications/programming/python.md b/docs/applications/programming/python.md
new file mode 100644
index 0000000..1180d39
--- /dev/null
+++ b/docs/applications/programming/python.md
@@ -0,0 +1,93 @@
+# Python
+
+## 安装 Python
+
+Linux 上装Python还是非常轻松的,因为不用装,大部分发行版自带。
+
+Linux 里面一般都是 `python3`。
+如果你想要用 `python` 这个命令, 可以装一个 `python-is-python3`, 来用软链接骗过操作系统(开个玩笑)。
+
+- Debian: `sudo apt install python-is-python3 -y`
+- Fedora: `sudo dnf install python-is-python3 -y`
+
+## 编写第一个脚本
+
+- 创建一个脚本
+
+```bash
+touch hello.py
+```
+
+- 写入内容
+
+```bash
+echo "print('hello python')" > hello.py
+```
+
+- 查看内容
+
+```bash
+cat hello.py
+
+# 会输出
+# print('hello python')
+```
+
+## 运行
+
+有很多Windows来的同志不知道怎么运行,但实际上非常简单。
+
+用法:
+
+```bash
+# python <要运行的脚本路径>
+
+python hello.py
+```
+
+这样你就成功运行起 Python 脚本了。
+实际上就是给 Python 指定需要运行的文件, 就这么简单。
+
+恭喜你在Linux上成功运行了Python脚本。
+
+## 编辑器
+
+- 如果你使用WSL, 推荐使用 VSCode 的 WSL 插件来连接写代码, 当然勇敢牛牛可以尝试 LazyVim 写代码
+- 如果你使用原生 Linux, 还是这两种推荐haha
+
+VSCode 资料很多, 我也用的比较少,可以直接上Bilibili搜索VSCode Python环境搭建
+[LazyVim入坑视频](https://www.bilibili.com/video/BV1TJCvYFE2T?t=286.5)
+
+## 库
+
+Python拥有规模庞大的PyPi库。通常,我们使用`pip`进行安装。但在Linux下,`pip`不一定会随着Python预装,因此需要使用包管理器安装。
+
+- Debian: `sudo apt install python3-pip`
+- Fedora: `sudo dnf install python3-pip`
+- Arch: `sudo pacman -S python-pip`
+
+!!! warning "系统依赖"
+ 使用Pip安装部分库时,可能会出现如下警告:
+ ```
+ error: externally-managed-environment
+
+ × This environment is externally managed
+ ╰─> To install Python packages system-wide, try 'pacman -S
+ python-xyz', where xyz is the package you are trying to
+ install.
+
+ If you wish to install a non-Arch-packaged Python package,
+ create a virtual environment using 'python -m venv path/to/venv'.
+ Then use path/to/venv/bin/python and path/to/venv/bin/pip.
+
+ If you wish to install a non-Arch packaged Python application,
+ it may be easiest to use 'pipx install xyz', which will manage a
+ virtual environment for you. Make sure you have python-pipx
+ installed via pacman.
+
+ note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
+ hint: See PEP 668 for the detailed specification.
+ ```
+ 由于系统的部分组件依赖Python的依赖,因而外来库可能破坏系统本身的依赖关系。
+
+ 这个时候,我们建议您使用`venv`创建虚拟环境,或者寻找发行版的软件源是否有对应的库可供安装(一般包名为`python3-库`或`python-库`)。 \ No newline at end of file