Arki 的每日 BUG 观察
41 subscribers
78 photos
1 video
3 files
228 links
分享每天写的bug
以前端为主
Download Telegram
#python strip

python的 str.strip([chars]) 和其他语言的 trim 不同, strip 会去除字符串头尾的每个 chars 字符,由于不好解释,请查看以下例子

>>>'1122A'.strip('12')
'A' # 删去了字符串头部所有 ‘1’ 和 ‘2’

另外还有只用来去除开头字符的 lstrip 和只用来去除结尾字符的 rstrip

如果只是想要移除字符串头部的指定字符串应该尝试使用其他方法

s = 'StringToRemove'
if line.startswith(s):
return line[len(s):]
#js tips

众所周知,使用 !! 可以快速将对象转换成 bool 类型,除此之外还可以仅使用 + 将对象转换为 number 类型,详情见例子(使用了TypeScript类型注释)

const myString: string = '1'
const n: number = +myString; // convert to number
> 1
const b: bool = !!myString; // convert to bool
> true
毫无意义的 js == 扫雷
#ts

typescript 中文件后缀 .ts .tsx 是严格区分的,你不能在 .ts 中写 JSX ,否则会出现各种奇怪的解析错误。老是没注意后缀,然后莫名其妙地 debug 5 分钟后才发现
#js eslint

使用 eslint 的时候发现 svg 文件被意外包含导致报错,尝试在eslint命令中使用 --ext 参数排除 svg 文件,但是没有生效,经过排查发现是 eslint 命令书写不规范导致的

// 错误命令(即使 ext 没有 svg 检查的时候还是会检查svg)
eslint --ext .ts,.tsx src/**

// 正确命令
eslint --ext .ts,.tsx src
挖到一个有趣的js挑战题

https://www.v2ex.com/t/509253
#############
剧透注意!!!!
上一条消息答案
如何检测网络是否已连接?

比较通用的方法是访问一个返回204(No Content)的页面

比如
https://g.co/generate_204
https://g.cn/generate_204

如果在国内可以选择清华大学的开源镜像站
https://mirrors.tuna.tsinghua.edu.cn/generate_204
#git

git push 的常用完整形式为
git push origin local_branch:origin_branch

比如 git push origin HEAD:master 为把当前分支推送到 origin 的 master 分支
我想把当前分支推送到远端的dev分支然后用 git push origin dev -f 把别人的提交抹掉了,所幸还有备份
大家对这个频道有什么意见建议,消息存在错误甚至想要搭讪,都欢迎通过 [google forms](https://forms.gle/jUknwjNmG9EaNDtJ8) 联系我(支持匿名)
Arki 的每日 BUG 观察 pinned «大家对这个频道有什么意见建议,消息存在错误甚至想要搭讪,都欢迎通过 [google forms](https://forms.gle/jUknwjNmG9EaNDtJ8) 联系我(支持匿名)»
#bash

# 如果存在 build 目录就删除该目录
if [ -d build ]; then
rm -rf build; # 结尾分号!!
fi
平时 bash 写的少,这种必须写分号的地方没写结果报错又找不到哪错QAQ
#git
如何将某个 dist 文件夹单独部署 gh-pages 分支?

大部分人可能重新建个git仓库push
cd dist
git init
git add .
git commit -m 'Deploy'
git remote add upstream [Upstream git URL]
git push origin gh-pages

实际上,使用 subtree 这个稀有命令更方便更优雅

git subtree split --prefix dist -b gh-pages # create a local gh-pages branch containing the splitted output folder
git push -f origin gh-pages:gh-pages # force the push of the gh-pages branch to the remote gh-pages branch at origin
git branch -D gh-pages

参考 [Deploying a subfolder to GitHub Pages](https://gist.github.com/cobyism/4730490)
* 该方案未亲自测试,如果有人踩坑请务必告知
#java
函数式的方法处理 null list
···
list = Optional.ofNull(list).orElse(Collecitons.emplyList())
···