换行符

换行符\r\n和\n的关系和区别可以追溯到60年前,打字机广泛被使用的时代。 在打字机还刚刚被发明的时候,人们输入完一行字之后,需要两个动作才能开始输入下一行的内容。 滚动滚轮,让纸张往上移动一行, 即是 \n 操作; 移动 打字的指针到 行首, 即是\r 。 上面两个操作没有顺序的要求, 1->2 ; 2->1 都可以。 windows Windows 操作系统 的文本对 new line的 编码 使用的是 2->1 的 组合操作; unix Linux/Unix 操作系统 则只使用操作 1 。 A line feed means moving one line forward. The code is \n. A carriage return means moving the cursor to the beginning of the line. The code is \r. Windows editors often still use the combination of both as \r\n in text files. Unix uses mostly only the \n. ...

November 17, 2021 · datewu

bash简介

本文会不定期更新 :) set 可以使用set命令改变shell脚本默认的执行流程。 比如 set -e 可以使得shell脚本遇到某一条命令出错( echo $? 不为0)时立即退出执行。 1 2 3 4 #/bin/bash set -e false echo you cannot see me, unless you comment out the 'set -e' flag, haha set详细文档 du 1 2 ❯ du -sh Downloads 4.1G Downloads wiki rm 1 rm $0 # 删除当前文件 for cleanup job nohup 在后台执行当前命令: 1 nohup /usr/sbin/script.sh & 默认情况下,进程是前台进程,这时就把Shell给占据了,我们无法进行其他操作,对于那些没有交互的进程, 我们希望将其在后台启动,可以在启动参数的时候加一个’&‘实现这个目的。 1 2 3 4 5 ❯ sleep 5 & [1] 34769 ✦ ❯ [1] + 34769 done sleep 5 ✦ ❯ 进程切换到后台的时候,我们把它称为job。切换到后台时会输出相关job信息,上面&的输出 [1] 34769 : [1]表示job ID 是1,11319表示进程ID是34769。切换到后台的进程,仍然可以用ps命令查看。 ...

November 17, 2021 · datewu

清理git submodule

当我们本地对git的submodule目录下的文件做了改动时,会发现不论是用git checkout . 还是 git clean -df都无法丢弃修改。使用git status命令查看工作树的状态时会有如下 报错信息git submodule modified content 错误 以hugo为例,当使用hugo server本地预览博客文章时, hugo会修改主题目录的内容。从而出现 git submodule modified content的问题。 1 2 3 4 5 6 7 8 9 10 11 12 ❯ git status 位于分支 main 您的分支领先 'origin/main' 共 1 个提交。 (使用 "git push" 来发布您的本地提交) 尚未暂存以备提交的变更: (使用 "git add <文件>..." 更新要提交的内容) (使用 "git restore <文件>..." 丢弃工作区的改动) (提交或丢弃子模组中未跟踪或修改的内容) 修改: themes/stack (修改的内容) 修改尚未加入提交(使用 "git add" 和/或 "git commit -a") 这个问题挺常见的,Google后使用下面两条命令即可清理submodule: ...

November 16, 2021 · datewu

vscode按键调整

今天发现vscodevim插件不能连续输入方向键j, 以为是插件的问题,关闭了插件。 发现在vscode里按住j不放,编辑器并不会连续输入j。 需要调整系统的dafaults关闭PressAndHold选项: enable key-repeating To enable key-repeating, execute the following in your Terminal, log out and back in, and then restart VS Code: 1 defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false # Enable key-repeating for vs code

May 9, 2021 · datewu

快慢指针

4月份腾讯面试的时候被问到如何在空间复杂度为O(1)前提下检查连表是否为闭环: 当时没想出来,面试官提醒用快慢指针也没写出来。 回到家里想了下,其实当时已经想出来了,没敢写出来: 1 2 3 4 5 6 7 8 9 10 11 func circular(head *ListNode) bool { slow, fast := head, head for fast != nil && fast.Next != nil { slow = slow.Next fast = fast.Next.Next if slow == fast { return true } } return false }

April 19, 2021 · datewu

自研

同事问我,把企业的harbor镜像仓库服务暴露到公网之后,有人暴力登陆怎么办? harbor默认是没有captcha的,google了很久也没看到。 咋办呢? 所以还是自研的产品好哦,随随便便就可以加个手机验证码。 ps:今天是在招商金科的最后一天了。

March 31, 2021 · datewu

React 17.0.2

今天看到react 17.0.2 发布一个礼拜了(快有1年没大的更新了),想升级试一试,在项目下执行 npm update指令,结果报错如下: 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 ✗ npm update npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! Found: @babel/[email protected] npm ERR! node_modules/@babel/core npm ERR! @babel/core@"7.12.3" from the root project npm ERR! @babel/core@"^7.9.0" from @svgr/[email protected] npm ERR! node_modules/@svgr/webpack npm ERR! @svgr/webpack@"5.4.0" from the root project npm ERR! 9 more (babel-jest, babel-loader, ...) npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer @babel/core@"^7.13.0" from @babel/[email protected] npm ERR! node_modules/@babel/preset-env/node_modules/@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining npm ERR! @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@"^7.13.12" from @babel/[email protected] npm ERR! node_modules/@babel/preset-env npm ERR! @babel/preset-env@"^7.9.5" from @svgr/[email protected] npm ERR! node_modules/@svgr/webpack npm ERR! @svgr/webpack@"5.4.0" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! See /Users/r/.npm/eresolve-report.txt for a full report. npm ERR! A complete log of this run can be found in: npm ERR! /Users/r/.npm/_logs/2021-03-30T08_44_22_160Z-debug.log 这个项目运行过 npm run eject,所以担心是eject造成的。 ...

March 29, 2021 · datewu

调试golang测试

调试某个go test程序的时候,需要实现confirm/approve功能: 测试完testCase1之后(或者说是某个断点),用户输入yes,执行下一个case,输入no, 则退出整个测试。 分析 下意识的觉得这个很好实现,调用fmt.Scan应该就OK了。 但是写的时候才发现,go test 会强制重定向os.Stdin = /dev/null忽略所有的 stdin输入, 所以没法使用 fmt.Scan来等待键盘(用户)的输入: 1 2 3 4 5 // fmt.Scan reads from os.Stdin, which is set to /dev/null when testing. // Tests should be automated and self-contained anyway, so you don't want // to read from stdin. // Either use an external file, a bytes.Buffer, or a strings.Reader and // call scan.Fscan if you want to test **the literal** `scan` Function. 解决方案 可以参考事件驱动,使用named pipes来实现confirm/approve功能: ...

October 14, 2020 · datewu

tcl入门

使用了一段时间Expect自动化工具简介里面的expect脚本,发现少了一些功能: 怎么给expect脚本传参数呢? expect怎么调用 bash/sh外部命令呢? expect怎么操作字符串呢? tcl 前面的文章Expect命令里面提到过,expect 使用的是Tcl/tk的语法。 所以 大家Google 一下 tcl tutorial就可以解决上面三个问题了。 tcl argc argc Tcl tutorial Tcl regexp new expect script 结合上面的3篇教程我把上篇文章自动化ssh 登陆的脚本优化如下: 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 35 36 37 38 39 40 41 42 43 44 #!/usr/bin/expect -f # for anyone not familar with expect # should read this awesome article # https://www.pantz.org/software/expect/expect_examples_and_tips.html if { $argc != 1} { puts "must set one argument for server_A host ip" puts "./login.tcl 1.1.2.2" exit 1 } set timeout 15 #set info [gets stdin] set info [exec privateRESTfullAPI2GetPwd -host $argv] set result [regexp {\"([^\"]*)\"[^\"]*\"([^\"]*)\"[^\"]*\"([^\"]*)\"} $info match host pw1 pw2] send_user "going to connected to server_A\n" spawn ssh -q -o StrictHostKeyChecking=no nobody@host expect { timeout { send_user "\ntimeout Failed to get password prompt, is VPN on?\n"; exit 1 } eof { send_user "\nSSH failure for server_A\n"; exit 1 } "*assword:" } send "$pwd1\r" expect { timeout {send_user "\nSSH failure for server_B\n"; exit 1 } "Last login:*" } send "su -\r" expect { eof { send_user "\nSSH failure check your password \n"; exit 1 } "密码" } send "$pw2\r" interact 简单解释上面的脚本: ...

May 19, 2020 · datewu

TCP/IP教程

本文不定期更新 :) 上个礼拜逛Hacker News看到推荐了一份写于1991年介绍TCP/IP协议的文章A TCP/IP Tutorial。 初略的扫了几眼,发现不错,加入了收藏夹。 昨天晚上抽出时间来细读了一遍觉得很有翻译的价值,于是试着翻译一下: Introduction This tutorial contains only one view of the salient points of TCP/IP, and therefore it is the “bare bones” of TCP/IP technology. It omits the history of development and funding, the business case for its use, and its future as compared to ISO OSI. Indeed, a great deal of technical information is also omitted. What remains is a minimum of information that must be understood by the professional working in a TCP/IP environment. These professionals include the systems administrator, the systems programmer, and the network manager. ...

April 13, 2020 · datewu