Nginx

安装 自动安装 # CentOS sudo yum install nginx # Ubuntu sudo apt-get install nginx 安装后nginx路径为/usr/sbin/nginx,配置文件为/etc/nginx/nginx.conf 手动安装 下载&解压 wget http://nginx.org/download/nginx-1.17.10.tar.gz tar zxvf nginx-1.17.10.tar.gz cd nginx-1.17.10 调整配置 ./configure --without-http_rewrite_module ./configure --prefix=/usr/local/nginx --with-http_ssl_module # 安装SSL模块 如果有的依赖库没有,需要先安装 # centos yum -y install pcre* #安装使nginx支持rewrite yum -y install gcc-c++ yum -y install zlib* yum -y install openssl openssl-devel # ubuntu apt-get install openssl apt-get install libssl-dev # 安装完后再次检查配置 ./configure 查看默认安装的模块 cat nginx-1.17.2/auto/options | grep YES 编译&安装 make sudo make install 修改配置 cd /usr/local/nginx/ vi conf/nginx.conf # 参看当前 Nginx 最终的配置 sbin/nginx -T # 检查配置是否有问题 nginx -t -c <配置路径> 启动Nginx cd /usr/local/nginx # 启动 sbin/nginx # 停止/退出/重启/重载配置 sbin/nginx -s stop/quit/reopen/reload 配置 nginx 开机自启 参考:https://www.nginx.com/resources/wiki/start/topics/examples/systemd/ ...

January 1, 2000

NLP

Terms NLU (Natural Language Understanding) / NLI (Natural Language Inferencing) NLG (Natural Language Generation) Tokenization (分词) Chinese Word Segmentation (中文分词) BPE/wordpiece/unigram Stemming (词干提取) Lemmatization (词形还原) Parts of speech tagging (词性标注) Named-entity Recognition (NER,命名实体识别) Chunking (分块) Language Model: A language model is a function that takes in a sequence of words and returns a probility distribution over all the possible next words in that sequence. autoregressive/causal language model masked language model (BERT) ...

January 1, 2000

Nodejs

Install # centos # https://github.com/nodesource/distributions#redhat-versions sudo yum install https://rpm.nodesource.com/pub_16.x/nodistro/repo/nodesource-release-nodistro-1.noarch.rpm -y sudo yum install nodejs -y --setopt=nodesource-nodejs.module_hotfixes=1 Install on Ubuntu How To Install Node.js on Ubuntu 22.04 版本管理 nvm curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash source ~/.bashrc nvm list-remote nvm install v20.10.0 node -v npm -v # change default node version nvm alias default 18 n # install sudo npm install -g n # 文档 n help # 切换版本 n # 安装指定版本 n 6.17.1 # 安装lts(newest Long Term Support official release) n lts # 删除版本 n rm 6.17.1 # 查看版本 node -v NodeJS 创建一个文件 index.js ...

January 1, 2000

Numpy-Pandas-SciPy

Numpy-Pandas-SciPy Numpy Basic Import import numpy as np Get shape x.shape Meshgrid x = np.arange(-5, 5, 0.1) y = np.arange(-5, 5, 0.1) xx, yy = np.meshgrid(x, y) z = np.sin(xx**2 + yy**2) / (xx**2 + yy**2) h = plt.contourf(x,y,z) Sort np.argmax(x) np.argsort(x) Matrix # change axes xx.transpose(1,0,2) Random Generate random samples # generate random integers over [low, high) with size d0*d1 from a uniform dist x = np.random.randint(low, high, (d0, d1)) # generate d0*d1*d2 samples from a uniform distribution over [0, 1) x = np.random.rand(d0, d1, d2) # generate d0*d1*d2 samples from a normal distribution over [0, 1) x = np.random.randn(d0, d1, d2) # generate n samples from a uniform distribution over [0, 1) x = np.random.random(n) x = np.random.sample(n) x = np.random.random_sample(n) x = np.random.randf(n) Make random choice ...

January 1, 2000

Nuxtjs

Quick Start Nuxt - Introduction 基于 Vue 的 SSR (Server Side Rendering) 框架 Init: npx nuxi@latest init <project-name> # or using vite npm create vite@latest Run: # npm npm run dev -- -o # nuxi npx nuxi dev Commands Nuxt - nuxi # get nuxt info npx nuxi info # init project npx nuxi init <project_name> # add modules npx nuxi module add <NAME> # creates a .nuxt directory and generates types. npx nuxi prepare # run dev npx nuxi dev --dotenv .env.dev --host 127.0.0.1 --port 3000 # build npx nuxi build --dotenv .env.prod # preview after build npx nuxi preview # run type check npx nuxi typecheck Config Nuxt Configuration ...

January 1, 2000

PostgreSQL

Install Ubuntu # client sudo apt-get install postgresql-client # server sudo apt-get install postgresql CentOS wget --no-check-certificate https://yum.postgresql.org/10/redhat/rhel-7-x86_64/postgresql10-libs-10.19-1PGDG.rhel7.x86_64.rpm wget --no-check-certificate https://yum.postgresql.org/10/redhat/rhel-7-x86_64/postgresql10-10.19-1PGDG.rhel7.x86_64.rpm wget --no-check-certificate https://yum.postgresql.org/10/redhat/rhel-7-x86_64/postgresql10-server-10.19-1PGDG.rhel7.x86_64.rpm sudo yum install postgresql10-libs-10.19-1PGDG.rhel7.x86_64.rpm sudo yum install postgresql10-10.19-1PGDG.rhel7.x86_64.rpm sudo yum install postgresql10-server-10.19-1PGDG.rhel7.x86_64.rpm sudo /usr/pgsql-10/bin/postgresql-10-setup initdb sudo systemctl start postgresql-10 sudo systemctl status postgresql-10 这时必须要切换到postgres用户sudo su - postgres才能链接,需要修改配置文件 sudo vi /var/lib/pgsql/10/data/pg_hba.conf 修改为 # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 trust 然后可以通过以下命令从客户端链接 ...

January 1, 2000

Prompts

Summurizing 结构 请为文章提供一个结构化的概要 理解 请介绍一下该技术的背景与发展历史。 请介绍一下主要特性与关键技术。 请列举上述介绍中涉及到的技术概念,请详细阐述涉及的每个概念,并举例说明。 (请重点解释上述概念间的差异与对比。) 使用 请介绍如何安装相关依赖或工具。 请介绍具体使用方式,并给出相应例子。 (简单介绍一下实际应用案例。) (使用中遇到哪些常见问题,如何解决。) 拓展 有没有类似工具,请对比其优劣 格式 请检查文章的格式,要求语句流畅,无错别字,格式美观,中英文间有空格,变量或命令用反括号。请直接返回校正后的文章。 Code Reading README 主要内容 依赖包,以及它们的功能 项目结构 文档、wiki Learning Summarising Summarise the above text into the most important points. Display the points as bullet points with short descriptions. Mind Map Create a mind map on the topic above. List out the central idea, main branches, and sub-branches. Active Recall I’ve recently immersed myself in studying [specific topic]. To ensure I’ve truly grasped the essence and intricacies, could you challenge my understanding by posing some deep, thought-provoking questions? This will not only test my recall of the main concepts and principles but also solidify my grasp on the finer details. ...

January 1, 2000

Python

Command # print version python -V # run python command python -c "print('Hello world!')" Python Files Header #!/usr/bin/python # -*- coding: utf-8 -*- Module A python file is a module main.py database.py const.py import module # method 1: import module import database client = database.Client() # method 2: import class from module from database import Client run a module as script python -m module_name # if the module is in parent/child/module_name.py python -m parent.child.module_name Package A folder of python files is a package ...

January 1, 2000

PyTorch

PyTorch PyTorch - QuickStart Basic # version torch.__version__ # PyTorch version torch.version.cuda # Corresponding CUDA version torch.backends.cudnn.version() # Corresponding cuDNN version torch.cuda.get_device_name(0) # GPU type # seed torch.manual_seed(0) torch.cuda.manual_seed_all(0) # GPU torch.cuda.is_available() os.environ['CUDA_VISIBLE_DEVICES'] = '0,1' torch.cuda.empty_cache() # clear GPU cache device = ( "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu" ) Tensor tensor = torch.randn(2, 3) # tensor info tensor.type() # Data type tensor.size() # Shape of the tensor tensor.shape # Shape of the tensor tensor.dim() # Number of dimensions # type convertions tensor = tensor.cuda() tensor = tensor.cpu() tensor = tensor.float() tensor = tensor.long() torch.set_default_tensor_type(torch.FloatTensor) # Set default tensor type # torch.Tensor <=> np.ndarray ndarray = tensor.cpu().numpy() tensor = torch.from_numpy(ndarray).float() tensor = torch.from_numpy(ndarray.copy()).float() # If ndarray has negative stride # 从只包含一个元素的张量中提取值 value = tensor.item() # torch.Tensor <=> PIL.Image # PyTorch中的张量默认采用N×D×H×W的顺序,并且数据范围在[0, 1],需要进行转置和规范化。 image = PIL.Image.fromarray(torch.clamp(tensor * 255, min=0, max=255 ).byte().permute(1, 2, 0).cpu().numpy()) image = torchvision.transforms.functional.to_pil_image(tensor) # Equivalently way tensor = torch.from_numpy(np.asarray(PIL.Image.open(path)) ).permute(2, 0, 1).float() / 255 tensor = torchvision.transforms.functional.to_tensor(PIL.Image.open(path)) # Equivalently way # np.ndarray <=> PIL.Image image = PIL.Image.fromarray(ndarray.astypde(np.uint8)) ndarray = np.asarray(PIL.Image.open(path)) # reshape tensor.reshape(shape) tensor.permute(0,2,1) # swap axes tensor.flatten() # 展成 1D 向量 tensor.squeeze() # 去掉维数为 1 的的维度 tensor.unsqueeze(dim=0) # 增加维度 # shuffle tensor = tensor[torch.randperm(tensor.size(0))] # Shuffle the first dimension # copy # Operation | New/Shared memory | Still in computation graph | tensor.clone() # | New | Yes | tensor.detach() # | Shared | No | tensor.detach().clone() # | New | No | # concatenate tensor = torch.cat(list_of_tensors, dim=0) tensor = torch.stack(list_of_tensors, dim=0) # one-hot N = tensor.size(0) one_hot = torch.zeros(N, num_classes).long() one_hot.scatter_(dim=1, index=torch.unsqueeze(tensor, dim=1), src=torch.ones(N, num_classes).long()) # non-zero torch.nonzero(tensor) # Index of non-zero elements torch.nonzero(tensor == 0) # Index of zero elements torch.nonzero(tensor).size(0) # Number of non-zero elements torch.nonzero(tensor == 0).size(0) # Number of zero elements # equal torch.allclose(tensor1, tensor2) # float tensor torch.equal(tensor1, tensor2) # int tensor # expand # Expand tensor of shape 64*512 to shape 64*512*7*7. torch.reshape(tensor, (64, 512, 1, 1)).expand(64, 512, 7, 7) # normalize F.normalize(tensor, dim=1) Dataloader from torch.utils.data import TensorDataset, Dataset, DataLoader train_ds = TensorDataset(x_train[:50000], y_train[:50000]) valid_ds = TensorDataset(x_train[50000:], y_train[50000:]) train_dl = DataLoader(train_ds, batch_size=mini_batch, shuffle=True, num_workers=4) valid_dl = DataLoader(valid_ds, batch_size=len(valid_ds)) for xb, yb in train_dl: pass 自定义dataset ...

January 1, 2000

RaspberryPi

安装 下载 Raspberry Pi Imager 烧录镜像 对于 Pi Zero W,目前烧录成功的镜像是 bullseye 32 bits:2024-03-12-raspios-bullseye-armhf-lite.img.xz,下载地址: Raspberry Pi - Operating system images 烧录时可以选择配置用户名密码,新的版本已经不再使用默认的 pi/raspberry 作为默认账密 烧录时可以配置 WiFi,iPhone 热点可用;配置勾选允许 SSH 登录 USB 连接 SSH 在文件 config.txt 中最后加上一行 dtoverlay=dwc2,表示开启 DesignWare USB 2.0 driver 在文件 cmdline.txt, 中的 rootwait 后面加上 modules-load=dwc2,g_ether,进入 USB Ethernet adapter 模式 常见问题 树莓派无法启动:检测 USB 线的问题,可能换成较粗较短的线后启动成功 配置了 USB 连接 SSH 后仍然无法连接 USB 线只支持供电不支持传输数据,换条 USB 线后解决 是否连接在树莓派的 data Micro USB 口上 WiFi 无法连接 iPhone 热点在开启一段时间后可能不再发送广播帧,需要手段开关 iPhone 热点后,然后在树莓派上 sudo wpa_cli -i wlan0 reconfigure WiFi 扫描 WiFi sudo apt update sudo apt install wireless-tools sudo iwlist wlan0 scan 连接 WiFi 在 /etc/wpa_supplicant/wpa_supplicant.conf 中加上 network={ ssid="your_ssid" psk="your_password" } 重启无线服务 sudo wpa_cli -i wlan0 reconfigure 检查是否连接成功 ifconfig wlan0 如有必要,可以手动更新 IP 租约 sudo dhclient -r wlan0 sudo dhclient wlan0 接口图 ...

January 1, 2000