分享一个 0 和 1 翻转的小技巧
1 ^ 1 = 0
0 ^ 1 = 1
顺便提一下我在知道这个技巧前都是这么干的
num ^= 11 ^ 1 = 0
0 ^ 1 = 1
顺便提一下我在知道这个技巧前都是这么干的
num = (num + 1) % 2 (笨死了#python
list.sort() 是原地排序,且永远返回 Nonepython
# wrong
listA = list(A).sort() # listA == None
# right
listA = list(A)
listA.sort()
# or
listA = sorted(list(A))
#css
在div中包裹图片,会发现img下面有几像素的空隙
原因:
默认 img 的
解决方式:
- 修改 img display
在div中包裹图片,会发现img下面有几像素的空隙
原因:
默认 img 的
display 为 inline
默认对齐方式 vertical-align 为 baseline 基线对齐,并不是与div的真实底部对齐,因此留有空隙解决方式:
- 修改 img display
img { display: block; }
- 修改 img 对齐方式为 bottom/middle/top img { vertical-align: bottom; }
- 修改 div div { line-height: 0; } 或 div { font-size: 0; }# 数据库死锁
#数据库
本篇讨论的不是程序造成的死锁,而是因意外(强行中断程序等)导致的数据表被锁住
## BUG定位
对异常表的任何增删操作 java 报异常
并且尝试对异常表表执行简单增删操作时操时总是提示
## 解决方法
- kill 阻塞的连接 使用
- kill 所有该数据库连接
- 重启数据库(简单粗暴)
#数据库
本篇讨论的不是程序造成的死锁,而是因意外(强行中断程序等)导致的数据表被锁住
## BUG定位
对异常表的任何增删操作 java 报异常
org.hibernate.exception.LockAcquisitionException 并且尝试对异常表表执行简单增删操作时操时总是提示
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
说明数据库可能被某个未提交的session阻塞了## 解决方法
- kill 阻塞的连接 使用
show processlist; 找到阻塞的连接,然后使用 kill $ID 干掉- kill 所有该数据库连接
sql然后运行生成的语句
-- 查询数据库的所有的进程并拼接kill语句
SELECT
concat( 'kill ', id, ';' )
FROM
information_schema.PROCESSLIST t
WHERE
t.db = '$LOCKED_DB';
- 重启数据库(简单粗暴)
#js
js 的默认排序是按照字母序递增排序,即使数组中全都是数字
js 的默认排序是按照字母序递增排序,即使数组中全都是数字
[2, 10, 1].sort() // [1, 10, 2]
// 按数字大小排序
[2, 10, 1].sort((x, y) => x - y) // [1, 2, 10]
#js
js 函数默认参数允许在没有值或 undefined 被传入时使用默认形参
js 函数默认参数允许在没有值或 undefined 被传入时使用默认形参
const test = (a=1) => a
test() // 1
test(null) // null
test(undefined) // 1
#tips #js
references: https://stackoverflow.com/questions/3115982/how-to-check-if-two-arrays-are-equal-with-javascript
// 简单比较数组是否相等
function arraysEqual(a1,a2) {
/* WARNING: arrays must not contain {objects} or behavior may be undefined */
return JSON.stringify(a1)==JSON.stringify(a2);
}
references: https://stackoverflow.com/questions/3115982/how-to-check-if-two-arrays-are-equal-with-javascript
Stack Overflow
How to check if two arrays are equal with JavaScript?
var a = [1, 2, 3];
var b = [3, 2, 1];
var c = new Array(1, 2, 3);
alert(a == b + "|" + b == c);
demo
How can I check these array for equality and get a method which returns true if they are equal?
var b = [3, 2, 1];
var c = new Array(1, 2, 3);
alert(a == b + "|" + b == c);
demo
How can I check these array for equality and get a method which returns true if they are equal?
#tips #js
references:https://stackoverflow.com/questions/36947150/how-to-return-a-default-value-from-a-map
// map 返回默认值
const map = new Map ([
[1, 'foo'], // default
[2, 'bar'],
[3, 'baz'],
]);
const mapProxy = new Proxy(map, {
get: function(target, id) {
// Cast id to number:
id = +id;
return target.has(id) ? target.get(id) : target.get(1);
},
});
console.log( mapProxy[3] ); // baz
console.log( mapProxy[10] ); // foo
references:https://stackoverflow.com/questions/36947150/how-to-return-a-default-value-from-a-map
Stack Overflow
How to return a default value from a Map?
Using the ES6 Proxy object it is possible to return a default value when a property does not exist in a plain object.
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/...
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/...
#git
git 默认对文件名大小写不敏感,因此在项目中修改文件名大小写时务必谨慎(已经重命名了的可能需要删除后重新添加
git 默认对文件名大小写不敏感,因此在项目中修改文件名大小写时务必谨慎(已经重命名了的可能需要删除后重新添加
// 配置git对大小写敏感
git config core.ignorecase false
Arki 的每日 BUG 观察
#js #tips # js 数组去重 js 数组本身没有带去重的函数 可以用一个简单的函数实现 const array = [1, 1, 2] // 多次使用 Array.prototype.unique = function() { return this.filter( (value, index, self) => { return self.indexOf(value) === index }) } array.unique() // 单次使用 array.filter((v,…
es6还可以使用
可以的话更推荐使用工具库的去重函数 如 lodash的
Set 去重
uniq = arr => [...new Set(arr)]
可以的话更推荐使用工具库的去重函数 如 lodash的
_.uniq(arr) 因为一些特殊的数值如 NaN 不好处理