LMLPHP后院

git pull 误操作后如何恢复技术

maybe yes 发表于 2017-05-24 23:30

习惯使用 git pull 不是无缘无故的,因为它确实好用,能更新整个项目所有分支。

但是,如果出错了,或者本身已经是最新的代码,误操作导致代码被污染怎么办?

$ git reflog feature-20170415

72f5ce3 feature-20170415@{0}: pull origin feature-20170415: Merge made by the 'recursive' strategy.
22a886b feature-20170415@{1}: rebase -i (finish): refs/heads/feature-20170415 onto a9ba6a4f760a9126f87ad49a0fd6c34834157df4
faa0e73 feature-20170415@{2}: commit: .
a9ba6a4 feature-20170415@{3}: rebase -i (finish): refs/heads/feature-20170415 onto 44102be15065bdf270a153a73a900642636a6a54
91f59b6 feature-20170415@{4}: commit: .
44102be feature-20170415@{5}: commit: .
723f02a feature-20170415@{6}: branch: Created from HEAD

spring boot jpa 多个数据源配置技术

maybe yes 发表于 2017-05-24 22:32

spring boot jpa 多数据源的配置,对于新手来讲还是不简单的,网上的很多资料都已经过时并且不靠谱。

application.properties 配置参考:

spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false
spring.http.encoding.charset=utf8


spring.datasource.url=jdbc:mysql://192.168.1.250:3306/main?useUnicode=true&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.sql-script-encoding=utf-8
spring.datasource.maximum-pool-size=100
spring.datasource.max-idle=10
spring.datasource.max-wait=10000
spring.datasource.min-idle=5
spring.datasource.initial-size=5
spring.datasource.validation-query=SELECT 1
spring.datasource.test-on-borrow=false
spring.datasource.test-while-idle=true
spring.datasource.time-between-eviction-runs-millis=18800

bar.datasource.url=jdbc:mysql://192.168.1.250:3306/project
bar.datasource.username=root
bar.datasource.password=
bar.datasource.driver-class-name=com.mysql.jdbc.Driver
bar.datasource.sql-script-encoding=utf-8

通过 UA 来识别浏览器和操作系统技术

maybe yes 发表于 2017-05-23 23:03

通过 UA 来判断浏览器及版本信息和操作系统类型及版本信息,其实意义不大,也是不太准的。一般这种只适用于浏览器请求识别,如果是 APP 客户端一般也不会设置这样的字段,至少会换种方式或名字。如果要更加准确的判断这些信息,应该在客户端完成识别。

即使意义不大,还得尝试去做。

写这种代码,比较费时间,因为不仅仅是技术,而是需要大量的搜集工作。找了一些开源的软件包,大的吓人,有些竟然依赖网络请求,这样就很慢且不稳定。发现一个网上的接口,一看就是专业的。useragentstring.com,不过这个接口太慢了。

分享一下,找起来不容易啊,尤其的微软的 Windows。

preg_match('/(firefox|chrome|msie|safari|360|uc|maxthon|qq)[\s\/]+([\d\.]+)/i', $user_agent, $matches);
if (isset($matches[1])) {
    $browser = $matches[1];
}
if (isset($matches[2])) {
    $browser_version = $matches[2];
}
$data['browser'] = $browser; 
$data['browserVer'] = $browser_version; 

$operate_system = '';
if (strpos($user_agent, 'Windows NT 6.1')) {
    $operate_system = 'Windows7';
}
if (strpos($user_agent, 'Windows NT 5.1')) {
    $operate_system = 'Windows XP';
}
if (strpos($user_agent, 'Windows NT 6.4')) {
    $operate_system = 'Windows 10';
}
if (strpos($user_agent, 'Windows NT 6.3')) {
    $operate_system = 'Windows 8.1';
}
if (strpos($user_agent, 'Windows NT 6.2')) {
    $operate_system = 'Windows 8';
}
if (strpos($user_agent, 'Windows NT 6.0')) {
    $operate_system = 'Windows vista';
}
if (strpos($user_agent, 'Mac OS X')) {
    $operate_system = 'Mac OS X';
}
if (strpos($user_agent, 'iPhone')) {
    $operate_system = 'iPhone';
}
if (strpos($user_agent, 'iPad')) {
    $operate_system = 'iPad';
}
if (strpos($user_agent, 'Android')) {
    $operate_system = 'Android';
}
if (strpos($user_agent, 'Linux')) {
    $operate_system = 'Linux';
}

如何让 VIM 不生成备份文件技术

maybe yes 发表于 2017-05-23 22:55

vim 编辑器在编辑文件的时候经常会到处生成备份文件,并且备份文件的文件名没有什么匹配规律,以致一度被认为是一个很脏的编辑器。

方法一,关闭备份:

set nobackup

方法二,设置备份目录:

set backupdir=/tmp

MySQL 开启通用查询日志技术

maybe yes 发表于 2017-05-23 22:46

有时候对一些东西不熟悉,就必须要对相关的东西熟悉,一起配合起来才能查出问题。

MySQL 开启通用日志的方法,临时开启:

sql> set global log_output=file;
sql> set global general_log_file='/tmp/general.log';
sql> set global general_log=on;

关闭通用日志:

sql> set global general_log=off;
2024-04-26 19:02:14 1714129334 0.018255