Nginx
01 大概02 Nginx架构基础03 详解HTTP模块04 反向代理与负载均衡05 Nginx的系统层性能优化06 从源码视角深入使用Nginx OpenResty
Java并发编程笔记
01 可见性、原子性、有序性:并发的bug源头
在 32 位的机器上对 long 型变量进行加减操作存在并发隐患? long类型64位,所以在32位的机器上,对long类型的数据操作通常需要多条指令组合出来,无法保证原子性,所以并发的时候会出问题
进程与线程进程不占有CPU。操作系统会把CPU分配给线程。分到CPU的线程就能执行。并行,是同一时刻,两个线程都在执行。并发,是同一时刻,只有一个执行,但是一个时间段内,两个线程都执行了。
volatile
volatile 是一个类型修饰符。作为指令关键字,确保本条指令不会因编译器的优化而省略。
volatile 的特性:(1) 保证了不同线程对这个变量进行操作时的可见性,即一个线程修改了某个变量的值,这新值对其他线程来说是立即可见的。(2) 禁止进行指令重排序。(实现有序性)(3) volatile 只能保证对单次读/写的原子性。i++ 这种操作不能保证原子性。
volatile 的实现原理:(1) 变量的内存可见性是基于内存屏障(Memory Barrier)实现。内存屏障,又称内存栅栏,是一个 CPU 指 ...
Golang MVC structure
This MVC doesn’t use any golang web framework Use http for client and server communication, MUX for routing
structure:in the G:/go-work/src/mvc-example:
app/controllershome.go
app/modelstypes.go
app/routeroute.go
app/helpers
config/.env
app/main.go
modify & create:comment on app/controllers like this:
1234// "github.com/gorilla/mux"// "mvc_example/app/models"// "encoding/json"// log "github.com/sirups ...
go get cmd
go get cmd
go get下载导入路径指定的包及其依赖项,然后安装命名包,即执行go install命令。用法:go get [-d] [-f] [-t] [-u] [-fix] [-insecure] [build flags] [packages]
标记名称 描述-d 让命令程序只执行下载动作,而不执行安装动作。-f 仅在使用-u标记时有效,该标记会让命令程序忽略掉对已下载代码包的导入路径的检查。如下载并安装的代码包所属的项目是Fork的。-fix 让命令程序在下载代码包后先执行修正动作,而后再进行编译和安装。-insecure 使用非安全scheme(如HTTP)去下载指定的代码包。如果用的代码仓库(如公司内部的Gitlab)没有HTTPS支持,可以添加此标记。-t 让命令程序同时下载并安装指定的代码包中的测试源码文件中依赖的代码包。-u 让命令利用网络来更新已有代码包及其依赖包。默认情况下,该命令只会从网络上下载本地不存在的代码包,而不会更新已有的代码包。-v 打印出被构建的代码包的名字-x 打印出用到的命令
go install使 ...
upgrade mysql
mysql upgrade(from 5.6 to 8.0.18)
find installation location
open cmd type mysql,and then12345678910111213show variables like "%char%";+--------------------------+---------------------------------------------------------+| Variable_name | Value |+--------------------------+---------------------------------------------------------+| character_set_client | gbk || charact ...
configure apache in docker while docker is in WSL
Apache12345678910$ mkdir -p mkdir -p ~/apache/www ~/apache/logs ~/apache/conf$ cd apache~/apache$ touch Dockerfile~/apache$ vi Dockerfile~/apache$ touch httpd-foreground~/apache$ vi httpd-foreground~/apache$ chmod +x httpd-foreground...service docker start...service docker status~/apache$ docker build -t httpdliuying .
Then you’ll get this error: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
SSH12345678910 sudo cp /et ...
create cli by cobra
installcd to ../golang.org/x
12git clone https://github.com/golang/textgit clone https://github.com/golang/sys
download github.com/spf13/cobra/cobracd to its dirthen open cmd & type
1go install github.com/spf13/cobra/cobra
then use it:
1cobra init mycalc
Cobra-based application structure:
1234▾ appName/ ▾ cmd/ root.go main.go
cobra main.go structure:
123456789package mainimport ( "mycalc/cmd")func main() { cmd.Execute()}
when you ...
convertexceltodocx
Convert excelfiles to docx by python script1. dump your mysql database by sql commandopen sql file paste the content in the navicatformyssql, then export the filtered contents to xlsx format
2. Convert excelusing vs studio run the python script, convert it to md.
3. Convert mdopen cmd, navigate the target location of your excel files, run:
1pandoc xxx.md -o yyy.docx
regexp
Go inputs verification1. Numbers123456789101112131415getint, err := strconv.Atoi(r.Form.Get("num"))if err != nil { // error occurs when convert to number, it may not a Number}// check range of numberif getint > 100 { // too big}orif m, _ := regexp.MatchString("^[0-9]+$", r.Form.Get("num")); !m { return flase}
2. Chinese123if m, _ := rangexp.MatchString("^[\\x{4e00}-\\x{9fa5}]+$", r.Form.Get("Chi ...
userinfo_interface
接口一般需要写5个文件:controller + model + service + serviceImpl + DAO1. controller 一般由@RequestMapping和@ResponseBody构成
123456@RequestMapping(value = "路径", method = RequestMethod.GET, produces = "名称/json;charset=utf-8") @ResponseBody public ApiResult appUserList(@RequestParam(value = "入参",defaultValue = "") 入参类型 入参) #多个入参并列添加 {ApiResult apiResult = new ApiResult(); PageList<模型model> result = 对应的service.appUserList(入参之间逗号相隔); return GenericApiResultUt ...