Powershell PSReadLine 配置

实现类似于zsh和fish的命令高亮和提示效果

1
2
3
4
5
6
7
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadLineOption -Colors @{ InlinePrediction = "#666666" }
Set-PSReadLineOption -BellStyle none
Set-PSReadLineOption -HistorySearchCursorMovesToEnd

解决Kotlin下使用@Transactional等Spring代理类空指针异常

直接上代码

1
2
3
4
5
6
7
8
9
10
11
open class BaseController<T : BaseEntity>(val baseService: BaseService<T>) {

@Transactional
@AuthRequired
@PatchMapping("/{id}")
open fun updateById(@PathVariable("id") id: Long, @RequestBody entity: T): ResponseEntity<T> {
entity.id = id
return ResponseEntity.ok(baseService.updateById(entity))
}

}

访问controller时出现NullPointerException,此时baseService为null

阅读更多

解决Kotlin项目spring-boot-configuration-processor不生效

在尝试用kotlin写springboot项目时发现springboot的kotlin项目模板的注解处理器没生效,结果就是自定义的配置类在idea中没有语法提示,且有一堆黄线警告,解决方法就是用kapt进行注解处理
在build.gradle.kts加入

1
2
3
4
5
6
7
8
9
plugins {
...
kotlin("kapt") version "1.4.20"
}

dependencies {
...
kapt("org.springframework.boot:spring-boot-configuration-processor")
}

重新构建,这样就能正确生成spring-configuration-metadata.json

阅读更多

解决Java MySQL驱动中MySQL时区与JVM时区的转换问题

在MySQL中,当使用timestamp作为储存时间的类型时,其读写都与sessiontime_zone有关。当没有显式指定时,当前session的time_zone会继承全局设置

  • 当写入时,会根据当前session的time_zone转换成UTC时间,将其时间戳进行储存
  • 当读取时,会将UTC时间戳转换为session所设置的time_zone所对应的时间

根据其他资料在连接字符串中添加参数serverTimezone

阅读更多

Vue+GIN前后端分离项目打包成二进制

问题

使用GIN自带静态资源服务器需要设置一个子目录,而这对于Vue项目来说显然是不合理的,如果使用根目录则会和其他路由冲突,所以需要对静态资源针对性处理

原理

阅读更多

解决Debian 10接入Cloudflare Warp后IPv6优先级低于IPv4

编辑/etc/gai.conf

找到如下部分,取消前5行的注释

1
2
3
4
5
6
7
8
9
10
11
12
# label   <mask>   <value>
# Add another rule to the RFC 3484 label table. See section 2.1 in
# RFC 3484. The default is:
#
label ::1/128 0
label ::/0 1
label 2002::/16 2
label ::/96 3
label ::ffff:0:0/96 4
#label fec0::/10 5
#label fc00::/7 6
#label 2001:0::/32 7
阅读更多

将GIN的模板资源嵌入二进制

利用statik库将静态资源嵌入二进制,但是GIN并没有提供从http.FileSystem加载模板的方法,所以得手动去加载

主要实现

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
30
31
32
33
34
func initTemplates() *template.Template {
statikFS, err := fs.New()
if err != nil {
log.Fatal(err)
}
t := template.New("")
//找出所有扩展名为.gohtml的文件,将其解析为模板
err = fs.Walk(statikFS, config.TemplateDir, func(path string, info os.FileInfo, err error) error {
if filepath.Ext(info.Name()) == ".gohtml" {
f, err := statikFS.Open(path)
if err != nil {
return err
}

b, err := ioutil.ReadAll(f)
if err != nil {
return err
}

_, err = t.New(path[1:]).Parse(string(b)) //此处去掉 path 前的 / 来作为模板的文件名
if err != nil {
return err
}
}

return nil
})

if err != nil {
log.Println("Load templates error")
log.Fatal(err)
}
return t
}
阅读更多

解决Docker下Golang程序在Alpine镜像中不读取hosts文件

今天用Docker部署gost的时候发现gost没有使用hosts文件中指定的ip,遂查阅了一番资料,得知是缺少了/etc/nsswitch.conf文件,解决方法如下:

1
echo "hosts: files dns" > /etc/nsswitch.conf

这条命令可以在运行时加入,也可以在构建镜像时加入,Dockerfile如下:

阅读更多

IPsec over GRE隧道简易配置教程

为了能够顺利根据这篇文章打通隧道,最好了解并满足如下前提:

  • 两台具有公网IP的VPS A和B,其中至少有一台拥有独立IP,并且另一台如果是NAT VPS则需要内外映射端口一致,假设A的公网IP为1.1.1.1,B的公网IP为2.2.2.2
  • 设定隧道A端内网IP为10.0.0.1,B端内网IP为10.0.0.2
  • A、B两台机器系统为Debian 10
  • 关闭防火墙

配置GRE隧道

阅读更多

用curl进行校园网模拟认证

这个学期学校网络登陆方式从拨号换到了dr.com的网页认证,通过chrome F12打开开发者工具,查看其登录其实就是发了一个GET请求,如下
请求url:http://10.160.63.9:801/eportal/
参数:

  • c:值为Portal,无需改动
  • a:值为login,代表登录,登出则是logout
  • callback:值为dr加上一个精确到毫秒的时间戳,如dr1599458671000,该值代表登陆的时间,实测该值并不影响登录,估计与上网记录的统计有关
  • login_method:值为1,无需改动
  • user_account:登陆账号,如1234123123@telecom,一般账号为学号,后面的后缀则为选的运营商,电信是telecom,其他运营商未测试
  • user_password,登陆密码,默认为身份证后六位
  • wlan_user_ip:通过DHCP获取到的内网ip
  • wlan_user_mac:值为000000000000,无需改动
  • wlan_ac_ip:值为221.178.235.146,无需改动
  • wlan_ac_name:值为JSSUZ-MC-CMNET-BRAS-KEDA_ME60X8,无需改动
  • jsVersion:值为3.0,无需改动
  • _:值为一个精确到毫秒的时间戳,猜测是打开网页的时间,实测该值并不影响登录,估计与上网记录的统计有关

关于内网ip可在路由器上获取,时间戳同样可以直接获取,如下

阅读更多