phpMyAdmin登录MySQL8

MySQL8使用了新的密码验证插件,所以pma不能直接登录,解决办法是创建一个旧验证方式的用户和密码,比如用户www密码123456,然后就可以登录了

CREATE USER 'www'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
GRANT ALL PRIVILEGES ON *.* TO 'www'@'%';
FLUSH PRIVILEGES;

Win10设置绿色版谷歌浏览器为默认浏览器

第一步:将另外一台Win10电脑上安装好的谷歌浏览器,复制到当前电脑的指定目录下

安装目录:C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

第二步:修复注册表

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications]
"Google Chrome"="Software\\Clients\\StartMenuInternet\\Google Chrome\\Capabilities"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome]
@="Google Chrome"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\Capabilities]
"ApplicationDescription"="Google Chrome 浏览器是一款可高速运行网页和应用的网络浏览器。它快捷、稳定且易于使用。Google Chrome 浏览器内置的恶意软件和网上诱骗防护功能可让您更安全地浏览网页。"
"ApplicationIcon"="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe,0"
"ApplicationName"="Google Chrome"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\Capabilities\FileAssociations]
".htm"="ChromeHTML"
".html"="ChromeHTML"
".pdf"="ChromeHTML"
".shtml"="ChromeHTML"
".svg"="ChromeHTML"
".xht"="ChromeHTML"
".xhtml"="ChromeHTML"
".webp"="ChromeHTML"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\Capabilities\Startmenu]
"StartMenuInternet"="Google Chrome"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\Capabilities\URLAssociations]
"http"="ChromeHTML"
"https"="ChromeHTML"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\DefaultIcon]
@="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe,0"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\InstallInfo]
"ReinstallCommand"="\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" --make-default-browser"
"HideIconsCommand"="\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" --hide-icons"
"ShowIconsCommand"="\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" --show-icons"
"IconsVisible"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\shell]

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\shell\open]

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\shell\open\command]
@="\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\""

第三步:在系统设置里,设置谷歌浏览器为默认浏览器

阿里云绿网内容安全API

PHP版本:


define('AccessKeyId', 'AccessKeyId');
define('AccessKeySecret', 'AccessKeySecret');

/**
 *  获取签名
 */
function getSign($md5, $date, $rand)
{
    $data = array(
        "x-acs-version" => "2018-05-09",
        "x-acs-signature-nonce" => $rand,
        "x-acs-signature-version" => '1.0',
        "x-acs-signature-method" => "HMAC-SHA1",
    );
    ksort($data);
    $signUrl = '';
    foreach ($data as $k => $v) {
        $signUrl .= $k . ':' . $v . "\n";
    }
    $signUrl = sprintf("POST\napplication/json\n%s\napplication/json\n%s\n%s/green/text/scan", $md5, $date, $signUrl);
    $sign = base64_encode(hash_hmac('sha1', $signUrl, AccessKeySecret, true));
    return $sign;
}

/**
 *  发起 HTTP 请求
 */
function httpRequest($url, $body)
{
    $date = gmdate('D, d M Y H:i:s T');
    $md5 = base64_encode(md5($body, true));
    $rand = md5(rand(10000, 99999) . time());
    $sign = getSign($md5, $date, $rand);
    $header = array(
        'Accept: application/json',
        'Content-Type: application/json',
        'Content-MD5: ' . $md5,
        'Date: ' . $date,
        'x-acs-version: 2018-05-09',
        'x-acs-signature-nonce: ' . $rand,
        'x-acs-signature-version: 1.0',
        'x-acs-signature-method: HMAC-SHA1',
        'Authorization: acs ' . AccessKeyId . ':' . $sign,
    );

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
    $data = curl_exec($curl);
    $error = curl_error($curl);
    curl_close($curl);
    if ($error) {
        return $error;
    } else {
        return $data;
    }
}

/**
 *  内容检测
 */
function greenTextScan($content) {
    $api = 'https://green.cn-beijing.aliyuncs.com/green/text/scan';
    $body = [
        'scenes' => ['antispam'],
        'tasks' => []
    ];
    foreach($content as $k=>$v) {
        $body['tasks'][] = [
            'dataId' => $k,
            'content' => $v
        ];
    }
    return httpRequest($api, json_encode($body));
}

function main()
{
    echo greenTextScan(['需要检测的文本']);
}

main();

Javascript 数组操作

一 数组转换为字符串

var w = ['a', 'b', 'c'];
w.toString(); // "a,b,c"
w.join(''); // "abc"
w.join('-'); // "a-b-c"

二 数组添加元素

var w = ['a'];
w.push('b'); // w: ["a", "b"]
w.unshift('c'); // w: ["c", "a", "b"]

三 数组删除元素

var w = ['a', 'b', 'c'];
w.pop(); // c
// w: ['a', 'b'];
w.shift(); // a
// w: ['b'];
delete w[0]

四 合并数组

var w1 = ['a'];
var w2 = ['b'];
var w = w1.concat(w2); // ["a", "b"]

五 查找数组元素

var w = ['a', 'b', 'c'];
w.indexOf('b'); // 1
w.includes('c'); // true
w.find(function(v, i, a) {
    if (v === 'b') {
    // do something
    }
}); // 'b'
w.findIndex(function(v, i, a) {
    if (v === 'b') {
    // do something
    }
}); // 1
w.forEach(function(v, i) { 
    if (v === 'b') { 
    // do something
    }
});

六 反转数组元素

var w = ['a', 'b', 'c'];
w.reverse(); // ["c", "b", "a"]

七 数组切片

var w = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
w.slice(2, 4); // ["c", "d"]

八 数组元素排序

var w = [4, 'e', 'z', 2, 'a', 'q', 9];
w.sort(); // [2, 4, 9, "a", "e", "q", "z"]
var w = [4, 7, 3, 2, 5, 8, 9];
w.sort(function(a, b) {
    return a - b;
}); // [2, 3, 4, 5, 7, 8, 9]

九 数组筛选

var w = [4, 'e', 'z', 2, 'a', 'q', 9];
var _w = w.filter(function(i) { return i > 0; }); // [4, 2, 9]

Javascript 字符串操作

一 字符串转换

// int to string
var n = 1; 
n.toString();
String(n);
'' + n
// string to int
var s = '123a';
Number(s);
parseInt(s); // 123 十进制
parseInt(s, 16); // 4666 十六进制
parseFloat(s); // 123
s = '123'; s - 0;

二 字符串分割

var s = 'abcdef-123456';
s.split('-'); // ['abcdef', '123456']
s.split('-', 1); // ['abcdef']

三 字符串查找

var s = 'abcdef';
s.indexOf('e'); // 4
s.lastIndexOf('e'); // 4
s.charAt(4); // e

四 字符串替换

var s = 'abcabc';
s.replace('a', '1'); // "1bcabc"
s.replace(/a/g, '1'); // "1bc1bc"

五 字符串匹配

var s = 'abcdef-123456';
s.match('ef'); // ["ef", index: 4, input: "abcdef-123456", ...]
s.match(/\w+/); // ["abcdef", index: 0, input: "abcdef-123456", ...]
s.match(/\w+/g); // ["abcdef", "123456"]
s.search(/\d+/); // 7

var reg = /\w+/;
reg.exec(s); // ["abcdef", index: 0, input: "abcdef-123456", ...]

六 字符串切割

var s = 'abcdef-123456';
s.substr(1, 4); // "bcde"
s.substring(1, 4); // "bcd"
s.slice(-3, -1); // "45"

七 大小写转换

var s = 'abcDEF-123456';
s.toLowerCase(); // "abcdef-123456"
s.toUpperCase(); // "ABCDEF-123456"

八 去除空格

var s = '  abc  ';
s.trim(); // "abc"

九 附录:字符串对象的所有方法

length
anchor()
big()
blink()
bold()
charAt()
charCodeAt()
concat()
constructor()
endsWith()
fixed()
fontcolor()
fontsize()
includes()
indexOf()
italics()
lastIndexOf()
link()
match()
matchAll()
normalize()
padEnd()
padStart()
repeat()
replace()
search()
slice()
small()
split()
startsWith()
strike()
sub()
substr()
substring()
sup()
toLocaleLowerCase()
toLocaleUpperCase()
toLowerCase()
toString()
toUpperCase()
trim()
trimEnd()
trimLeft()
trimRight()
trimStart()
valueOf()
hasOwnProperty()
isPrototypeOf()

清理Win10我的电脑中的各个文件夹

REM 我的电脑

REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{f86fa3ab-70d2-4fc7-9c99-fcbf05467f3a} /f
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{24ad3ad4-a569-4530-98e1-ab02f9417aa8} /f
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{d3162b92-9365-467a-956b-92703aca08af} /f
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{088e3905-0323-4b02-9826-5d99428e115f} /f
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{3dfdf296-dbec-4fb4-81d1-6a3438bcf4de} /f
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{B4BFCC3A-DB2C-424C-B029-7FE99A87C641} /f
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{0DB7E03F-FC29-4DC6-9020-FF41B59E513A} /f

REM Onedrive

%SystemRoot%\SysWOW64\OneDriveSetup.exe /uninstall
REG Delete "HKEY_CLASSES_ROOT\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f
REG Delete "HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f

保存为del.cmd,右键管理员权限运行

vscode配置golang开发环境

一、安装 VSCode 和 Golang

二、在 go module 模式下加载工具包

mkdir test
cd test
go mod init test

三、配置代理

// set GOPROXY=https://proxy.golang.org
set GOPROXY=https://mirrors.aliyun.com/goproxy/

// GO 1.13+
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy,direct
go env -w GOSUMDB=sum.golang.google.cn

四、下载依赖包

go get github.com/stamblerre/gocode
rename %GOPATH%/gocode.exe %GOPATH%/gocode-gomod.exe

go get github.com/mdempsky/gocode
go get github.com/uudashr/gopkgs/cmd/gopkgs
go get github.com/ramya-rao-a/go-outline
go get github.com/acroca/go-symbols
go get golang.org/x/tools/cmd/guru
go get golang.org/x/tools/cmd/gorename
go get github.com/go-delve/delve/cmd/dlv
go get github.com/rogpeppe/godef
go get golang.org/x/tools/cmd/goimports
go get golang.org/x/lint/golint
go get golang.org/x/tools/gopls

开发环境镜像设置

一、阿里系镜像

# Composer
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

# npm
npm config set registry https://registry.npm.taobao.org --global
npm config set disturl https://npm.taobao.org/dist --global

# CentOS
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# epel
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

二、其他镜像

# GoProxy Win
set GOPROXY=https://proxy.golang.org

# GoProxy Linux
export GOPROXY=https://proxy.golang.org

Go Module 开发环境配置

一、初始化项目

mkdir go-app
cd go-app
go mod init app

二、设置第三方依赖包

go get github.com/go-sql-driver/mysql@v1.4.1
go get github.com/gin-gonic/gin@v1.3.0
go get github.com/gomodule/redigo/redis@v1.7.0

三、开始编码

package main

import (
	"database/sql"
	"log"

	"github.com/gin-gonic/gin"
	_ "github.com/go-sql-driver/mysql"
)

var db *sql.DB

func main() {
	databaseInit()
	defer db.Close()
	gin.SetMode(gin.ReleaseMode)
	r := gin.Default()
	r.GET("/", IndexAction)
	r.GET("/user/:name", UserAction)
	r.Run()
}

func databaseInit() {
	var err error
	db, err = sql.Open("mysql", "root:123456@tcp(127.0.0.1:3306)/wordpress")
	if err != nil {
		log.Fatalln(err)
	}
	db.SetMaxIdleConns(500)
	db.SetMaxOpenConns(500)
	err = db.Ping()
	if err != nil {
		log.Fatalln(err)
	}
}

func IndexAction(c *gin.Context) {
	c.JSON(200, gin.H{"message": "index"})
}

func UserAction(c *gin.Context) {
	var ID int
	err := db.QueryRow("SELECT ID FROM wp_users WHERE user_login = ?", c.Param("name")).Scan(&ID)
	if err == nil {
		c.String(200, "Hello %d", ID)
	} else {
		c.String(200, "Hello nobody")
	}
}

四、生成本地依赖

go mod vendor

五、运行

go run -mod=vendor main.go

PHP构建JWT签名

// Google Oauth2.0 JWT
function JWT() {
    $time = time();
    $header = ['alg' => 'RS256', 'typ' => 'JWT'];
    $claims = [
        'iss' => 'app@01.iam.gserviceaccount.com', 
        'scope' => 'https://www.googleapis.com/auth/photoslibrary',
        'aud' => 'https://www.googleapis.com/oauth2/v4/token', 
        'exp' => $time + 3600,
        'iat' => $time
    ];
    $msg = Base64URLEncode(json_encode($header)) . '.' . Base64URLEncode(json_encode($claims));
    $privateKey = "-----BEGIN PRIVATE KEY-----\nKEY\n-----END PRIVATE KEY-----\n";
    $sign = '';
    openssl_sign($msg, $sign, $privateKey, 'SHA256');
    return $msg . '.' . Base64URLEncode($sign);
}

function Base64URLEncode($input) {
    return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
}

echo JWT();