Arki 的每日 BUG 观察
41 subscribers
78 photos
1 video
3 files
228 links
分享每天写的bug
以前端为主
Download Telegram
#好文推荐
wjndante的“概率与随机”三部曲之其一——如何用计算机生成“真随机”
http://bbs.ngacn.cc/read.php?tid=8477978&_fp=6
Forwarded from 荔枝木
🤣 JavaScript 的圣三位一体
#js #redux
action的枚举性质很适合使用es6的 Symbol ,但不推荐这么做,因为symbol无法序列化导致损失了redux的一些性质,比如无法把整个状态序列化保存到localStorage后无损还原回来,一些扩展工具如redux-devtools-extension(可通过参数手动支持)也因此(?)没有支持symbol.
因此在redux的action中请使用字符串,同时在redux中也请尽可能避免使用无法序列化的数据结构

相关讨论
[redux | Action types as symbols](https://github.com/reduxjs/redux/issues/4)
#js 对字符串进行运算前,将字符串转换成数字是个好习惯
#js trim
js 自带的 trim 函数是没有参数的,只能移除 white space and line terminator characters (空格和换行) 因此需要移除其他自定符号时请使用工具库的 trim 函数 (如lodash的 _.trim([string=''], [chars=whitespace]) )

'abc\n'.trim('a') // 'abc'
_.trim('abc\n', 'a') // 'bc\n'
#python
http://blog.jobbole.com/42706/
Python 新手常犯错误(第一部分)
TL;DR
不要用一个可变的值作为默认值
>>> def foo(numbers=[]):
... numbers.append(9)
... return numbers
>>> foo()
[9]
>>> foo()
[9, 9]
>>> foo()
[9, 9, 9]

正确做法
def foo(numbers=None):
if numbers is None:
numbers = []
numbers.append(9)
return numbers
如果变量是一个布尔值,变量名最好加上 is、has 或 can 作为前缀https://twitter.com/samantha_ming/status/1043578525339418624
#bug ASCII表中英文字母是不连续的,大写字母跟随着几个符号然后才是小写字符,因此判断字符是否英文字符不能使用 `c >= 'A' && c <= 'z'` 应该使用 `(c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')` 或者使用正则表达式判断 `[A-Za-z]`
#c
-2147483648/-1
整数除以 0 可能会触发 SIGFPE,最小的 INT(-2147483648)除以 -1 也可能会触发
#include<stdio.h>
int main() {
int a = -2147483648; // 0x80000000
int b = -1;
int ans = a / b;
printf("%d\n", ans);
return 0;
}
运行结果 Floating point exception
Forwarded from YSC 的频道
C++11 开始,std::string 可以直接用作缓冲区,不需要用另外一块空间保存,然后再拷贝到 std::string 中。
https://stackoverflow.com/a/39200666
在 C++11/14 中可以使用 &str.front()&str[0] 来获取地址,C++17 中 str.data() 加入了非 const 的重载,可以直接用 str.data() 来获取地址。
str.size() 是缓冲区的长度,可以用 str.resize(length) 分配空间。
#js (日常黑js
#js
'([{'.search('(')
// Uncaught SyntaxError: Invalid regular expression: /(/: Unterminated group

string.search 字符串的查询方法参数是一个 `RegExp 如果给的是字符串,会被强制转换为 RegExp

因此查询普通字符串的时候,请使用`string.indexOf`
#js
判断空数组请不要使用 === 直接与空数组比较
[] === [] // false
请使用
if (Array.isArray(array) &&  array.length === 0) {
// empty array
}
10行代码踩了两个坑我也是醉了 _(:з)∠)_
#js
js string有两个substr相关的方法 string.substrstring.substring
两个方法的去别在于参数不同
string.substr takes parameters as (from, length).
string.substring takes parameters as (from, to).

console.log("abc".substr(1,2)); // returns "bc"
console.log("abc".substring(1,2)); // returns "b"
#java #spring
springboot的 @Value 注解并不能注入 static 的变量
如果想注入static,必须另外新建setMethod

@Component
public class GlobalValue {
// @Value("${datasource}") ×
public static String DATABASE;

@Value("${datasource}")
public void setDatabase(String db) {
DATABASE = db;
}
}
#java
java应用打成jar包之后classpath下的resources文件不能用File的方式读取

@Value("classpath:menu.json")
private Resource res;

// res.getFile(); ×
res.getInputStream();