Poi浏览器在macOS上PAC代理失效

我之前一直是用的Poi浏览器的PAC代理功能来上舰, 见这篇文章。但是从今年年初开始,PAC代理功能就不work了,本来我以为是这个问题,但是在后来的10.6.0版本中http-proxy-agent和pac-proxy-agent都更新了,PAC代理功能在我的系统上却还是不work,具体的表现为http请求总是返回200的空response,而https请求却没有问题,很不幸,舰C的游戏URL至今还是http的。今天我终于花了半天时间找了找原因,现记录在此。

首先考虑的就是POI的代码中还是有BUG,于是我从源码直接跑POI,PAC代理竟然神奇地work了,我以为是10.6.0之后修了什么bug,于是重新build,安装,又不行了……于是我花了好久看代码,但是看不出什么所以然,毕竟直接run是没有问题的,build之后问题才会出现。POI使用electron-builder来进行打包,我也不是很清楚怎么debug打包后的application,于是我尝试在proxy.es文件中用console.log来打log。

由于这些log是打在electron的main process中的,所以它们不会出现在开发者工具的console里,而是会输出到stdout,所以我尝试着从terminal里运行打包后的application,命令如下

1
open -W /Application/poi.app

但是这样是不会在terminal中打出log的,怀疑与macOS的application加载机制有关。于是我就直接运行了POI的binary而不是整个application

1
/Application/poi.app/Contents/MacOS/poi

这样就可以看到console.log的输出了。神奇的事情发生了,通过这种方式打开POI,PAC代理的问题消失了,功能完全正常,当时我就一脸黑人问号.jpg。这是什么神奇的bug?搞了半天是macOS的application加载机制作祟。我猜测是electron+electron-builder+pac-proxy-agent+macOS产生了什么不为人知的神奇化学反应导致了这个现象。

知道了问题,那么只要直接跑/Application/poi.app/Contents/MacOS/poi就可以了。我用macOS自带的Automator建了一个一行shell语句的application

1
nohup /Applications/poi.app/Contents/MacOS/poi > /dev/null 2>&1 &

然后就可以通过运行这个application来启动PAC正常工作的POI了。

我为什么不热衷于升级软件了

在我正式开始学习计算机知识,也就是大学之前的几年里,我想大概是从我家刚有电脑的初中开始吧,我都是一个热衷于把电脑里的软件更新到最新版的人。然而从那以后的八年里,我越来越懒于更新软件了,手机也好,电脑也好,平板也好,软件商店上常常五六十个App更新我都能做到视而不见了。

刷题的况味

写下这个标题的时候我才发现我竟然一直都不是很确定“况味”这个词到底是个什么意思,忘记了中学时候在什么地方看到过这个词,估计是在哪一堂语文课或者哪一次语文阅读的时候遇到的吧。去查了一下才知道跟“滋味”是差不多的,这么说来放在标题也还是挺贴切的。

似乎读不下去书了

我最近发现自己的读书能力下降的非常厉害,不仅是读书的效率还是读书的意愿都不像以前那么好了。

我的WFH配置

不知不觉在家工作已经快要两个月了,其间经历了一次跳槽来Google,在新公司家里也呆了一个月了。因为两周前Pichai说可能要一直WFH的年底,于是不得不为长期作战做准备了,添置了一些新的硬件。现在我对于WFH的环境还是比较满意的了。

在网页中使用Service Worker发送通知

最近写了一个上班时摸鱼用的舰C远征计时工具。React的部分很快就搞定了,但是因为远征结束的时候要发送一个浏览器通知,我以前没有写过这种东西,所以走了很多弯路花了不少时间,最终还是把功能实现了。

这是我第一次使用Service Worker,也没有花很多时间去研究,所以肯定会有很多疏漏。

给博客加了GitHub Action自动部署

虽然很久没有写博客了,但是题还是在做的,最近也跳了槽来了Google。前几天有人给我的BGM report仓库开PR,由于不想手动try,所以就加了个简单的GitHub Action来自动测。今天给博客也加上了Action,以后就不用手动run Hexo命令来生成然后再push了。

Action Workflow:https://github.com/Shell32-Natsu/Shell32-Natsu.github.io/blob/src/.github/workflows/deploy.yml

今天还写了个远征计时的小玩意儿,用React的小App,也用了Action自动部署到GitHub Pages。

LeetCode 1156. Swap For Longest Repeated Character Substring

Given a string text, we are allowed to swap two of the characters in the string. Find the length of the longest substring with repeated characters.

Example 1:

1
2
3
Input: text = "ababa"
Output: 3
Explanation: We can swap the first 'b' with the last 'a', or the last 'b' with the first 'a'. Then, the longest repeated character substring is "aaa", which its length is 3.

Example 2:

1
2
3
Input: text = "aaabaaa"
Output: 6
Explanation: Swap 'b' with the last 'a' (or the first 'a'), and we get longest repeated character substring "aaaaaa", which its length is 6.

Example 3:

1
2
Input: text = "aaabbaaa"
Output: 4

Example 4:

1
2
3
Input: text = "aaaaa"
Output: 5
Explanation: No need to swap, longest repeated character substring is "aaaaa", length is 5.

Example 5:

1
2
Input: text = "abcdef"
Output: 1

Constraints:

  • 1 <= text.length <= 20000
  • text consist of lowercase English characters only

LeetCode 1155. Number of Dice Rolls With Target Sum

You have d dice, and each die has f faces numbered 1, 2, ..., f.

Return the number of possible ways (out of fd total ways) modulo 10^9 + 7 to roll the dice so the sum of the face up numbers equals target.

Example 1:

1
2
3
4
Input: d = 1, f = 6, target = 3
Output: 1
Explanation:
You throw one die with 6 faces. There is only one way to get a sum of 3.

Example 2:

1
2
3
4
5
Input: d = 2, f = 6, target = 7
Output: 6
Explanation:
You throw two dice, each with 6 faces. There are 6 ways to get a sum of 7:
1+6, 2+5, 3+4, 4+3, 5+2, 6+1.

Example 3:

1
2
3
4
Input: d = 2, f = 5, target = 10
Output: 1
Explanation:
You throw two dice, each with 5 faces. There is only one way to get a sum of 10: 5+5.

Example 4:

1
2
3
4
Input: d = 1, f = 2, target = 3
Output: 0
Explanation:
You throw one die with 2 faces. There is no way to get a sum of 3.

Example 5:

1
2
3
4
Input: d = 30, f = 30, target = 500
Output: 222616187
Explanation:
The answer must be returned modulo 10^9 + 7.

Constraints:

  • 1 <= d, f <= 30
  • 1 <= target <= 1000

Invoke Jenkins Jobs from BitBucket Server by Webhook

I just added unit tests and am planning to add functional test scripts to one of my project. What comes to your mind when you work on a project every day, already have had test scripts and there is a Jenkins server available? Right, automate it!

My compay uses BitBucket server. However, although there are several BitBucket server plugins available, all of them are not free (and they are even not cheap!). So far, I just want to invoke a Jenkins job when some events happen. Should we pay thousands of dollars for such a easy (relatively) use case? So I decide to find some free alternatives.