- 函数和类可以支持多种类型,增加的程序的可扩展性
- 不必写多条函数重载,联合类型声明,增强代码的可读性
- 灵活控制类型之间的约束
总结: 泛型不仅可以保持类型的一致性,又不失程序的灵活性,同时也可以通过泛型约束,控制类型之间的约束。从代码的上来看,可读性,简洁性,远优于函数重载,联合类型声明以及 any 类型的声明。
| import * as React from 'react' | |
| import styled from 'styled-components' | |
| import { observable } from 'mobx' | |
| import { Tooltip, Input, message } from 'antd' | |
| import { Icon } from '@/components' | |
| import { observer } from 'mobx-react' | |
| // 匹配非字母数字下划线空格中文的字符 | |
| const reg = /[^a-zA-Z0-9_\s\u4e00-\u9fa5]/g |
HTTP/2 抓包
使用 TLS/SSL 加密,都是随着连接生成有变化的(???)
Mac 下
$ export SSLKEYLOGFILE=/Users/username/sslkeylogs/output.log
$ open -a Google\ Chrome
打开 wireshark
yum install python2-certbot-nginx
certbot --nginx --niginx-server-root <your_nginx_install_path> -d <your_domains>
注意: 两个参数 nginx 安装路径 和 真实域名,另外该命令会将配置写到 nginx 配置中
| #!/bin/sh | |
| # create self-signed server certificate: | |
| read -p "Enter your domain [www.example.com]: " DOMAIN | |
| echo "Create server key..." | |
| openssl genrsa -des3 -out $DOMAIN.key 1024 |
| #!/bin/bash | |
| # Install Shadowsocks on CentOS 7 | |
| echo "Installing Shadowsocks..." | |
| random-string() | |
| { | |
| cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1 | |
| } |
| axios({ | |
| url: 'http://localhost:5000/static/example.pdf', | |
| method: 'GET', | |
| responseType: 'blob', // important | |
| }).then((response) => { | |
| const url = window.URL.createObjectURL(new Blob([response.data])); | |
| const link = document.createElement('a'); | |
| link.href = url; | |
| link.setAttribute('download', 'file.pdf'); | |
| document.body.appendChild(link); |
| import * as mysql from 'mysql2' | |
| const Client = require('ssh2').Client | |
| const ssh2mysql = { | |
| _conn: null, | |
| _mysql_conn: null, | |
| /** | |
| * @param obj sshConfig SSH Configuration as defined by ssh2 package |
| const mysql = require('mysql2') | |
| const tunnel = require('tunnel-ssh') | |
| const ssh2mysql = { | |
| _conn: null, | |
| _mysql_pool: null, | |
| /** | |
| * @param obj sshConfig SSH Configuration as defined by ssh2 package |