Libraries

任务调度 schedule install pip install schedule usage import schedule # add schedule job schedule.every(10).seconds.do(lambda: print("running")) # run scheduler while True: schedule.run_pending() time.sleep(1) add job with parameters def func(name: str): print(f"My name is {name}") schedule.every(5).seconds.do(func, name="Tom") while True: schedule.run_pending() time.sleep(1) Apscheduler Install pip install apscheduler Triggers:任务触发逻辑 cron:cron 格式触发 interval:固定时间间隔触发 date:在某固定日期触发一次 combine:组合条件触发 Scheduler BlockingScheduler: 阻塞式,当程序只运行这个 scheduler 时使用 BackgroundScheduler:调度器在后台运行 Executor ThreadPoolExecutor:默认使用多线程执行器 ProcessPoolExecutor:如果是 CPU 密集型任务可以使用多进程执行器 Job store:如果任务调度信息存在内存中,当程序退出后会丢失,可以其他存储器进行持久化存储 MemoryJobStore: 默认使用内存存储 SQLAlchemyJobStore MongoDBJobStore etc. 创建 scheduler ...

January 1, 2000

MacOS

使用技巧 系统配置 Accessibility -> Reduce Motion: on 触摸板 轻点 三指查询 快捷键 系统默认 Cmd + Shift + 5: 截屏或录屏 Cmd + Shift + .:显示隐藏文件夹 Fn + F11:显示桌面 自定义快捷键 All Applications Show Next/Previous Tab: cmd-option-left/right iTerm New Tab Here: ctrl-T New Tab with Current Profile: cmd-shift-T Shadowsocks Switch On/Off: ctrl-S 密码规则 获取密码配置文件,用vim打开 pwpolicy getaccountpolicies > ~/Desktop/file.plist vim ~/Desktop/file.plist 把第一行:Getting global account policies 整行删除 修改各个配置规则 policyAttributeExpiresEveryNDays:过期天数 policyAttributePasswordHistoryDepth:历史密码深度 policyAttributePassword matches ‘^$|.{4,}+’:不少于4个字符的密码 policyAttributePassword matches ‘.+’:(前面的正则已经被改掉了)包含至少1个数字和1个字母字符 policyAttributePassword matches ‘.{8,}’:包含至少8个字符 应用配置文件 ...

January 1, 2000

Make

Make bin2hex: bin2hex.c gcc -Wall -Werror -o bin2hex bin2hex.c .PHONY: clean clean : rm bin2hex Arguments makefile: target: echo argument is $(argument) command make foo=bar target

January 1, 2000

Markdown

Markdown headers header3 header4 header5 Content blablabla List list: item1 item2 item3 first second third Link link: www.baidu.com Table header1 header2 header3 content1 content2 content3 content4 content5 content6 quotation quota Code echo "hello world" import pandas as pd print("hello world") a = 1 + 2 SELECT * FROM table WHERE ds = 20100304 Formular $$ a = b + c $$ sum_(i=1)^n i^3=((n(n+1))/2)^2 Diagram About Mermaid Mermaid Live Editor Flowchart Top -> Bottom graph TB A --> B Botton -> Top ...

January 1, 2000

Maven

Maven Install Maven Ubuntu sudo apt install maven Manually 下载Binary tar.gz archive文件 安装 mkdir ~/.java cd ~/.java tar zxvf apache-maven-3.5.4-bin.tar.gz vi ~/.bash_profile export MAVEN_HOME=/Users/yizhenchen/.java/apache-maven-3.5.4 export M2_HOME=$MAVEN_HOME export PATH=$PATH:$MAVEN_HOME/bin source ~/.bash_profile 检查是否安装成功 mvn -v echo $M2_HOME 首次运行完mvn后会在"~“目录下创建”.m2"文件夹,作为本地仓库 配置Maven 修改配置文件 $MAVEN_HOME/conf/settings.xml ~/.m2/settings.xml 使用Maven 在项目中添加pom.xml文件 groupId: 一般为package名 artifactId: 一般为项目名 version: 版本 目录结构: Project pom.xml src main java resources test java resources target <groupId>here.there</groupId> <artifactId>MavenTest</artifactId> <version>1.0</version> 命令 clean:清空target目录 complie:编译工程 package:执行打包 install:发布到仓库 运行 ...

January 1, 2000

Mini Program

Mini Program WXML 与 HTML 语法类似:WXML 使用 {{value}} 绑定数据 使用 wx:for 遍历数组 <view> <view class="title">Demo</view> <view> <view> <button type="default" size="mini" bind:tap="onChangeCnt">add cnt</button> cnt: {{cnt}} </view> <view> <button type="primary" size="mini" bind:tap="onChangeStr">reverse str</button> str: {{str}} </view> <view> <button type="warn" size="mini" bind:tap="onModifyObj">modify obj</button> obj.name: {{obj.name}}, obj.age: {{obj.age}} </view> <view> <button type="default" size="mini" bind:tap="onAppendArr">append arr</button> <button type="default" size="mini" bind:tap="onModifyArr">modify arr</button> <view wx:for="{{arr}}" wx:key="index"> index: {{index}}, name: {{item.name}}, age: {{item.age}} </view> </view> </view> </view> WXSS 与 CSS 语法类似:WXSS ...

January 1, 2000

MongoDB

安装 Install MongoDB Community Edition on Ubuntu 启动 sudo systemctl start mongod sudo systemctl status mongod Docker Dockerhub - mongo docker pull mongo:7.0.0 docker run -d \ --name mongodb \ --restart unless-stopped \ -v /data/mongodb:/data/db \ -p 27017:27017 \ -e MONGO_INITDB_ROOT_USERNAME=mongoadmin \ -e MONGO_INITDB_ROOT_PASSWORD=secret \ mongo:7.0.0 配置 TLS Configure mongod and mongos for TLS/SSL docker run -d \ --name mongodb \ --restart unless-stopped \ -v /data/mongodb:/data/db \ -v /home/your_username/.ssl:/etc/ssl/mongodb \ -p 27017:27017 \ -e MONGO_INITDB_ROOT_USERNAME=your_username \ -e MONGO_INITDB_ROOT_PASSWORD=your_password \ mongo:latest \ mongod --tlsMode requireTLS \ --tlsCAFile /etc/ssl/mongodb/ca.pem \ --tlsCertificateKeyFile /etc/ssl/mongodb/mongodb.pem 或者通过配置文件 mongod.conf 设置 ...

January 1, 2000

Monitoring

Monitoring InfluxDB Documentaion 官方文档:Get started with InfluxDB 镜像配置:influxdb Docker Official Images 函数详解:Prometheus数学理论基础 Install # docker docker run \ --name influxdb \ -p 8086:8086 \ -v $PWD/config.yml:/etc/influxdb2/config.yml \ -v /data/influxdb:/var/lib/influxdb2 \ influxdb:2.2.0 Setup docker exec influxdb influx setup \ --username {username} \ --password {password} \ --org {org} \ --bucket default \ --retention 8760h \ --force Query from(bucket:"example-bucket") |> range(start: -15m) |> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system" and r.cpu == "cpu-total" ) Prometheus Documentaion 官方文档:GETTING STARTED 安装Node Exporter 在要监控的机器上安装 Node Exporter ...

January 1, 2000

Mysql

Mysql 安装 Docker 安装 docker volume create mysql-volume docker run -d --name mysql \ -e MYSQL_ROOT_PASSWORD=1234 \ -v mysql-volume:/var/lib/mysql \ -p 3306:3306 \ mysql:5.7.35 # client mysql -h 127.0.0.1 -P 3306 -u root -p 1234 # 注意,docker启动的mysql如果用localhost连会报找不到socket的错误 # 可以把host换成127.0.0.1,或者用tcp连接 mysql -h localhost --protocol=tcp -P 3306 -u root -p 1234 DockerHub - mysql mycli pip install mycli mycli -h 127.0.0.1 -P 3306 -u root -p 1234 基础操作 CREATE DATABASE /* 创建新数据库 */ ALTER DATABASE /* 修改数据库 */ CREATE TABLE /* 创建新表 */ ALTER TABLE /* 变更(改变)数据库表 */ ALTER TABLE table ADD COLUMN /* 添加列 */ ALTER TABLE table MODIFY /* 修改列 */ DROP TABLE /* 删除表 */ CREATE INDEX /* 创建索引(搜索键) */ DROP INDEX /* 删除索引 */ mysql -u yourusername -p yourpassword yourdatabase < text_file # 执行sql文件 Learning SQL 启动 # MacOS sudo mysqld_safe mysql -u root -p # login as root create database bank #create a new database create user 'user'@'localhost' identified by 'password'; /* 创建本地访问用户 */ create user 'user'@'%' identified by 'password'; /* 创建远程访问用户 */ grant all privileges on bank.* to 'ychen'@'localhost' identified by 'password'; /* 配置权限 */ grant all privileges on bank.* to 'ychen'@'%' identified by 'password'; flush privileges; quit; mysql -u ychen -p use bank; 创建表 CREATE TABLE person (person_id SMALLINT UNSIGNED, fname VARCHAR(20), lname VARCHAR(20), gender ENUM('M','F'), birth_date DATE, street VARCHAR(30), city VARCHAR(20), state VARCHAR(20), country VARCHAR(20), postal_code VARCHAR(20), CONSTRAINT pk_person PRIMARY KEY (person_id) ); # describe table person DESC person; # create another tabel with foreign key CREATE TABLE favorite_food (person_id SMALLINT UNSIGNED, food VARCHAR(20), CONSTRAINT pk_favorite_food PRIMARY KEY (person_id, food), CONSTRAINT fk_fav_food_person_id FOREIGN KEY (person_id) REFERENCES person (person_id) ); 修改定义 ALTER TABLE person MODIFY person_id SMALLINT UNSIGNED AUTO_INCREMENT; ALTER TABLE person ADD occupation VARCHAR(20); 插入行 INSERT INTO person (person_id, fname, lname, gender, birth_date) VALUES (null, 'William','Turner', 'M', '1972-05-27'); 查找行 SELECT person_id, fname, lname, birth_date FROM person; # 按列显示 SELECT person_id, fname, lname, birth_date FROM person \G SELECT person_id, fname, lname, birth_date FROM person WHERE person_id = 1 ORDER BY lname; 更新行 UPDATE person SET street = '1225 Tremont St.', city = 'Boston', state = 'MA', country = 'USA', postal_code = '02138' WHERE person_id = 1; 删除行 DELETE FROM person WHERE person_id = 2; 查看tables SHOW TABLES; Query Primer Clause name Purpose Select Determines which columns to include in the query’s result set From Identifies the tables from which to draw data and how the tables should be joined Where Filters out unwanted data Group by Used to group rows together by common column values Having Filters out unwanted groups Order by Sorts the rows of the final result set by one or more columns The SELECT Clause things can be included in the SELECT clause ...

January 1, 2000

Network

Link Layer 查看网络接口 ip # 查看网络接口详细信息 ip address ip address show ${interface} ip -brief address # 查看链路层接口 ip -brief link x # 查看路由表 ip route # 查看arp表 ip neighbour ifconfig interface configuration command ifconfig # 查看所有接口 ifconfig -a # 查看接口eth0信息 ifconfig eth0 # Disable eth0 interface ifconfig eth0 down # Enable eth0 interface ifconfig eth0 up # Assign IP address to eth0 interface ifconfig eth0 ${ip_address} /sys/class/net ll /sys/class/net 查看arp表 arp # 查看arp表 arp # 清空arp缓存 sudo arp -a -d Network Layer icmp ping # echo ping # ping with fixed size data to check MTU ping -c 4 -s 1600 ${target_ip} traceroute # 发现IP接力路径(route)上的各个路由器 traceroute 路由转发 route # 查看路由表 route -n # 添加路由规则 sudo route add -net ${ip_address} netmask ${netmask_address} gw ${gw_address} # 删除路由规则 sudo route del -net ${ip_address} netmask ${netmask_address} gw ${gw_address} routel # list routes with pretty output format routel routef # flush routes routef /proc/sys/net/ipv4/ip_forward # 启用路由转发 echo "1" > /proc/sys/net/ipv4/ip_forward # 禁用路由转发 echo "0" > /proc/sys/net/ipv4/ip_forward Public IP curl ifconfig.me curl myip.ipip.net dig +short myip.opendns.com @resolver1.opendns.com Transport Layer TCP telnet # tcp连接 telnet ${ip} ${port} nc # Listen on a specified port and print any data received nc -l ${port} # send UDP data echo "Hello, UDP!" | nc -u ${receiver_ip} ${port} # Connect to a certain port nc ${ip_address} ${port} # 扫描指定ip指定端口 nc -z -v ${ip_address} ${port} 过滤 iptables IPTables ...

January 1, 2000