Jan 26
又遇到一个灵异的 intellij idea 问题。

背景:在项目 P 的同一个 Module M 下面, PKG P1 需要 import PKG P2 下面的 C1 和 C2 两个 class。

现象:import C1 成功,但是import C2失败;然而通过 mvn clean install 是可以正常完成编译的。

点击在新窗口中浏览此图片

删除 project 下的 .idea 目录重新 import 并没有解决这个问题。

在另一个同学的电脑上尝试,报的错竟然不一样,是在 C2 这个 class 下无法 import 另一个 class C3,但同样可以通过 mvn 命令行完成编译。

通过 Google 搜到 StackOverflow 的这个 thread:

  https://stackoverflow.com/a/66167190/802910

解决方案很简单:删掉 idea 的cache 目录,让它重建就好了。

在 windows 下,这个目录位于 %LOCALAPPDATA%\JetBrains\IdeaIC2021.2\caches (注意替换为自己版本号)

在 mac 下,目录应该是 ~/Library/Caches/JetBrains/IdeaIC2021.2

似乎 IDEA 本身也有清空 cache 的功能(File -> Invalidate Caches...),下次遇到再验证一下。

Aug 11
# 现象

手头有一个比较大的maven project,拆成了十几个module,如果我要在 Intellij IDEA 跑个单测什么的,就会报错,各种依赖找不到,即使 pom.xml 里是明明白白写着:

点击在新窗口中浏览此图片

依然无法识别,连 lombok 和 junit 都不行:

点击在新窗口中浏览此图片

尽管 idea 很好心地给了帮助 "Add JUnit4 to classpath",点击后也只是在 pom.xml 里再添加一次,并没有什么卵用。

这个问题有个很灵异的现象是,每次用 "mvn clean install" 整体编译的时候是正常的,但是在 idea 跑 test case,或启动某个 main,就会报错。


# 排查

打开 Project Structure 可以看到,这个 module 的 dependency 全是空的:

点击在新窗口中浏览此图片

说明 pom.xml 文件应该是有坑。

查看 maven reload 的output,发现是了问题是某个dependency没有指定版本号

引用
[ERROR] org.apache.maven.artifact.InvalidArtifactRTException: For artifact {org.apache.flink:flink-streaming-java_2.11:null:jar}: The version cannot be empty.


参考其他 module 指定正确的版本号:

引用
<version>1.10.1</version>


再重新reload,问题就解决了。


# 回顾

再回头想想前面提到的灵异现象,从结果倒推,大概是因为把项目作为整体编译的时候,同一个package只能有一个版本,即使模块A没有指定版本,只要模块B有指定,就能正常引用。

之前还遇到过另一个现象,整体编译没问题,但是在 iDEA 里跑单测的时候,会发现引用了旧版本,其实也是同样的问题了。


完。
Aug 9
遥想第一次听说Google Authenticator已经是 7年前的事情 了,那时候它还托管在 Google Code 上(缅怀)。

说来惭愧,那会儿我就已经用着 SecureCRT 好几年了,就在D厂的时候大家都在用的那个D版。今年终于咬牙买了个正版,突然意识到它的Logon Script可以用来搞这个两步认证,上网搜了一下,已经有大神写好放在 gist 上了,于是抄了一把,略作改动,贴在这里。

注意:
1. 记得要把 SecureCRT session option里 Login Actions → "Display logon prompts in terminal window" 勾上。
2. 这个版本是windows版用的,保存成py文件;用mac版的同学,要看下scrt的脚本引擎是py2还是py3,py3的话,得用原作者这个 gist 里的另一个版本

# $language = "python"
# $interface = "1.0"

import hmac, base64, struct, hashlib, time, json, os

TOTP_KEY = 'YOUR_TOTP_KEY'
YOUR_PASSWD = 'PASSWORD'

def get_hotp_token(secret, intervals_no):
  """This is where the magic happens."""
  key = base64.b32decode(normalize(secret), True) # True is to fold lower into uppercase
  msg = struct.pack(">Q", intervals_no)
  h = hmac.new(key, msg, hashlib.sha1).digest()
  o = ord(h[19]) & 15
  h = str((struct.unpack(">I", h[o:o+4])[0] & 0x7fffffff) % 1000000)
  return prefix0(h)


def get_totp_token(secret):
  """The TOTP token is just a HOTP token seeded with every 30 seconds."""
  return get_hotp_token(secret, intervals_no=int(time.time())//30)


def normalize(key):
  """Normalizes secret by removing spaces and padding with = to a multiple of 8"""
  k2 = key.strip().replace(' ','')
  # k2 = k2.upper()  # skipped b/c b32decode has a foldcase argument
  if len(k2)%8 != 0:
    k2 += '='*(8-len(k2)%8)
  return k2


def prefix0(h):
  """Prefixes code with leading zeros if missing."""
  if len(h) < 6:
    h = '0'*(6-len(h)) + h
  return h


def main():
  tab = crt.GetScriptTab()

  if tab.Session.Connected != True:
    crt.Dialog.MessageBox("Session Not Connected")
    return

  tab.Screen.Synchronous = True
  tab.Screen.WaitForStrings(['[MFA auth]:'])
  vc = get_totp_token(TOTP_KEY)
  tab.Screen.Send("{vc}\r\n".format(vc=vc))
  tab.Screen.WaitForStrings(['Opt>'])
  tab.Screen.Send("relay2\r\n")
  if tab.Screen.WaitForString('password:', 1):
      tab.Screen.Send("{pwd}\r\n".format(pwd=YOUR_PASSWD)) #鄙厂的relay后面还有个relay
  return

main()


REF:
https://gist.github.com/hex-ci/a8c58ac049c4b3a05ef2d6f9d98193c2
Aug 1
~/.bashrc 中加上以下内容即可:
引用
export LANG=zh_CN.UTF-8


如果 git 命令(如 git diff)下仍有代码,可以再增加
引用
export LESSCHARSET=UTF-8


如果 vim 下依然有乱码,在 .vimrc 中增加
引用
set encoding=utf-8
set termencoding=utf-8


--

参考资料:
- Mac下使用SecureCRT时中文乱码问题解决
  https://blog.csdn.net/BabyFish13/article/details/101463105

- 记一次secureCRT中文乱码解决过程
  https://yunchangyue.github.io/blog/tools/2018/11/16/securecrt/
May 12

Go网络实战三篇 不指定

felix021 @ 2021-5-12 23:46 [IT » 网络] 评论(0) , 引用(0) , 阅读(2279) | Via 本站原创
Dec 24
备查。

#允许 felix021 用户免密 sudo 为所欲为
felix021  ALL=(ALL:ALL) NOPASSWD: ALL

#允许 adm 这个 group 免密 sudo 为所欲为
%adm  ALL=(ALL:ALL) NOPASSWD: ALL

# Cmnd alias specification
Cmnd_Alias APT_CMD=/usr/bin/apt-get install *, /usr/bin/apt install *

# 允许所有用户用 root 权限执行 APT_CMD 下的所有命令
ALL ALL=(root) NOPASSWD: APT_CMD
Aug 20

https耗时分析 不指定

felix021 @ 2020-8-20 18:34 [IT » 网络] 评论(0) , 引用(0) , 阅读(1823) | Via 本站原创
简单记一下:

$ cat curl-format.txt
time_namelookup:      %{time_namelookup}\n
time_connect:        %{time_connect}\n
  time_appconnect:    %{time_appconnect}\n
  time_pretransfer:  %{time_pretransfer}\n
  time_starttransfer: %{time_starttransfer}\n

$ curl -w '@curl-format.txt' -o /dev/null -s -L "https://www.baidu.com"
time_namelookup:      0.004
time_connect:        0.018
  time_appconnect:    0.050
  time_pretransfer:  0.050
  time_starttransfer: 0.065



或者

$ go get github.com/davecheney/httpstat

$ httpstat https://www.baidu.com
...

  DNS Lookup  TCP Connection  TLS Handshake  Server Processing  Content Transfer
[      0ms  |          9ms  |        105ms  |            10ms  |            0ms  ]
            |                |              |                  |                  |
  namelookup:0ms            |              |                  |                  |
                      connect:10ms          |                  |                  |
                                  pretransfer:116ms            |                  |
                                                    starttransfer:126ms            |
                                                                                total:126ms 
分页: 2/103 第一页 上页 1 2 3 4 5 6 7 8 9 10 下页 最后页 [ 显示模式: 摘要 | 列表 ]