char *, char[], and string in C++
 char *, char[], and string in C++
1234567891011121314151617181920212223// char * and char[] to stringchar * p = "Hello, world!\n";char c[] = "Hello, world!\n";std::string str1(p), str2(c);cout << str1 << str2 << endl;// string to char * and char[]char cc[10];char *pp;strcpy(cc, str1.c_str());strcpy(pp, str1.c_str());cout << cc << pp << endl;// char[] to char *char ccc[] = "Hello, world!\n";char *ppp = ccc;cout << ppp << endl;// char * to char[]cha ...
Servlet
 Servlet
 Servlet执行原理
当服务器接收到客户端浏览器的请求后,会解析请求URL路径,获取访问的Servlet的资源路径。
查找web.xml文件,是否有对应的标签体内容。
如果有,则再找到对应的全类名。
tomcat会将字节码文件加载进内存,并且创建其对象。
使用其方法。
 Servlet中的生命周期方法
被创建:执行init方法,只执行一次
默认情况下,第一次被访问时,Servlet被创建
在标签下配置
在第一次被访问时,创建:的值为负数
在服务器启动时,创建:的值非负数
多个用户同时访问时,可能存在线程安全问题
解决办法:尽量不要在servlet中定义成员变量,即使定义了,也不要对其修改值
提供服务:执行service方法,执行多次
被销毁:执行destroy方法,只执行一次
服务器正常关闭时,servlet被销毁之前执行,用来释放资源
Win10关闭占用某一端口的进程
 Win10关闭占用某一端口的进程
 查看端口占用情况
1netstat -ano | findstr 端口号
 关闭该进程
 使用任务管理器关闭
根据PID找到该进程,结束任务
 使用命令关闭
1taskkill -PID 进程号 -F
SQL
 SQL
 登录MySQL数据库
1mysql -u root -p
 导入.sql数据库文件
12USE RUNOOB;SOURCE Websites.sql;
 SELECT
SELECT语句用于从数据库中选取数据,结果存储在一个结果表中,成为结果集。
1SELECT column_name, column_name FROM table_name;
1SELECT * FROM table_name;
从"Websites"表中选取所有列:
1SELECT * FROM Websites;
从"Websites"表中选取"name"和"country"列:
1SEKECT name, country FROM Websites;
 SELECT DISTINCT
在表中,一个列可能会包含多个重复值,有时您也许希望仅仅列出不同(distinct)的值。DISTINCT 关键词用于返回唯一不同的值。
1SELECT DISTINCT column_name, column_name FROM tabl ...
修改hosts以连接GitHub
 修改hosts以连接Github
当使用git克隆仓库时可能出现443: Time out的错误,用浏览器访问GitHub也不行时,可能的解决办法是修改hosts文件。
 查询IP地址
首先在https://www.ipaddress.com/上查询github.com和github.global.ssl.fastly.net的IP地址(可能会发生变化)。
现在查到github.com的IP地址为140.82.114.3,github.global.ssl.fastly.net的IP地址为199.232.69.194。
 修改hosts
在C:\Windows\System32\drivers\etc目录下的hosts文件中增加以下两行:
12140.82.114.3 github.com199.232.69.194 github.global.ssl.fastly.net
 清除DNS缓存
修改完hosts需要清除DNS缓存:
执行以上步骤后,可能就已经能连接上GitHub了。
pyinstaller
 pyinstaller打包pyqt5程序
 参数
-D: 生成一个文件夹,里面有很多依赖库(默认参数,建议使用)
-F: 仅生成一个.exe程序(除了程序非常简单,不建议使用)
-w: 运行.exe程序时不显示cmd窗口
-c: 图标路径,作为程序icon
-p: 增加程序依赖文件
 流程
假设要打包一个main.py,有一个依赖文件UartHelper.py,建议流程如下:
1pyinstaller main.py -p UartHelper.py
或
1pyinstaller main.py -D -p UartHelper.py
一般第一次都不会成功,在cmd运行dist/main目录下的main.exe。由于没有使用-w参数,可以看到报错信息:
这里报错:unable to find Qt5Core.dll on PATH,将dist/main目录下的Qt5Core.dll复制到dist/main/PyQt5/Qt/bin目录。再次运行,运行成功:
接下来可以使用-w参数使程序运行时不产生cmd窗口,生成后仍然需要复制Qt5Core.dll文件:
1pyinstall ...
chocolatey
 Windows包管理器chocolatey的安装与使用
 安装
以管理员身份运行cmd,输入:
1@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
 使用chocolatey安装make
1choco install make
安装成功:
123456789101112131415161718192021222324252627C:\Users\WenQinghua ...
Github使用技巧
 GitHub使用技巧
 项目管理
可以方便地管理项目,每个小块可以拖动
 搜索技巧
in:name spring boot starts:>3000 forks:>100
仓库名字包含"spring boot"、stars>3000、forks>100
in:readme spring boot starts:>1000
readme中包含"spring boot"、starts>1000
in:description 微服务 language:java pushed:>2019-09-03
description中包含"微服务"、语言为Java、最后一次更新晚于2019-09-03
Magic Numbers
 Magic Numbers
 Addison Wesley - Hacker’s Delight
		The basic trick is to multiply by a sort of  reciprocal of the divisor d, approximately 232/d2^{32}/d232/d
, and then to extract the leftmost 32 bits of the product. The  details, however, are more complicated, particularly for certain divisors such as 7.
		Let us first consider a few specific examples. These illustrate the code that will be generated by the general method. We denote registers as follows:
n - the input integer(numerator)
M - ...

![char *, char[], and string in C++](https://cdn.jsdelivr.net/gh/WenQinghua/image@master/keyboard-g7e6c447cc_640.52gcpjqsf140.webp)




