零碎的知识点

零碎的知识点

为记录一些零碎的知识点

mysql

1. 创建数据表的int后面的括号

1
2
3
CREATE TABLE Test (
number INT(3),
);

这里 int(3) 中的3表示两个占位符

1
2
3
4
5
6
当你插入1的时候数据库会显示
001
当你插入2的时候数据库会显示
002
当你插入12的时候数据库会显示
012

python

1. 自动生成requirements.txt 文件

生成 requirements.txt 文件
pip freeze > requirements.txt

安装 requirements.txt 依赖
pip install -r requirements.txt

2. 运行时间记录

一个偷懒…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import datetime

start_time = datetime.datetime.now()

# this is loop

end_time = datetime.datetime.now()

seconds = (end_time - start_time).seconds
start = start_time.strftime('%Y-%m-%d %H:%M')

minutes = seconds // 60
second = seconds % 60
print((end_time - start_time))
time_str = str(minutes) + '分钟' + str(second) + "秒"
print("程序从 " + start + ' 开始运行,运行时间为:' + time_str)

3. 动态构造变量

原理 :

  1. 使用 exec()
  2. 使用 locals() 或者 globals()
1
2
3
4
5
6
7
8
9
10
11
12
# exec() 形式
for i in range(5):
exec('var1_{} = {}'.format(i, i))
print(var1_0, var1_1, var1_2, var1_3 ,var1_4)

# locals() 形式
var2 = locals()
for i in range(5):
var2['n' + str(i)] = i
print(n0, n1, n2, n3, n4)
print(var2['n0'])
print(var2)

4. 将一组数据分为多组

这里是分成了三组

1
2
3
4
5
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
step = 3
b = [a[i:i + step] for i in range(0, len(a), step)]
print(b)

5.pip 安装东西失败了

如果是碰到这个了

1
2
raise ReadTimeoutError(self._pool, None, 'Read timed out.')
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

C:\user\userName 目录下新建一个文件夹和一个文件
形式如下
pip/pip.ini

文件内容如下

1
2
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

这个操作是把python源换成了清华源

5. Cookie格式化

1
2
3
cookies = requests.utils.dict_from_cookiejar(response.cookies)
print('你的cookie:', ''.join([''.join(cookie + '=' + cookies.get(cookie) + ';') for cookie in cookies]))

PHP

究极正则

1
$pattern = '/(?<=符号)[^<]*?(?=符号)/';

电脑知识

命令行激活系统和Office

  • 支持 Windows Vista/7/8/8.1/10
  • 支持 Windows server 2008/2008R2/2012/2012R2/2016/2019
  • 支持 Office 2010/2013/2016/2019
  • 支持 Office 365

Win 激活

  1. 管理员权限进入命令行
  2. 输入以下命令
    1
    slmgr /skms kms.v0v.bid && slmgr /ato   

Office 激活

核心原理 到这个的目录下执行这个 OSPP.VBS

  1. 管理员权限进入命令行
  2. 切换命令执行目录
  • Office2016、Office365、Office2019 进入默认安装目录
    • 32位office:
      cd C:\Program Files (x86)\Microsoft Office\Office16
    • 64位office:
      cd C:\Program Files\Microsoft Office\Office16
  • Office2013 进入默认安装目录
    • 32位office:
      cd C:\Program Files (x86)\Microsoft Office\Office15
    • 64位office:
      cd C:\Program Files\Microsoft Office\Office15
  • Office2010 进入默认安装目录
    • 32位office:
      cd C:\Program Files (x86)\Microsoft Office\Office14
    • 64位office:
      cd C:\Program Files\Microsoft Office\Office14
  1. 输入以下命令
    1
    cscript ospp.vbs /sethst:kms.v0v.bid && cscript ospp.vbs /act

JavaScript

图片上传缩略图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>缩略图实现</title>
</head>
<body>
<div>
<img id="img" src="#" alt="缩略图">
</div>
<div>
<input type="file" name="" id="file" onchange="changepic()">
</div>
</body>
<script>
function changepic() {
var reads = new FileReader();
f = document.getElementById('file').files[0];
console.log(f);
reads.readAsDataURL(f);
reads.onload = function (e) {
document.getElementById('img').src = this.result;
console.log(this.result);
}
}
</script>
</html>

ab工具

1
ab -n 总的请求数 -c 并发数 url

内网穿透工具

教程 https://zhuanlan.zhihu.com/p/163425163

项目地址 https://github.com/open-dingtalk/pierced

1
2
3
# 使用方法
# http
ding -config=ding.cfg -subdomain=mobenw 5566

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!