# 数据库死锁
#数据库
本篇讨论的不是程序造成的死锁,而是因意外(强行中断程序等)导致的数据表被锁住
## 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 不好处理https://medium.com/javascript-non-grata/the-top-10-things-wrong-with-javascript-58f440d6b3d8
#js
The Top 10 Things Wrong with JavaScript
#js
The Top 10 Things Wrong with JavaScript
Medium
The Top 10 Things Wrong with JavaScript
JavaScript has a reputation for being one of the worst programming languages in existence, and for good reasons! JavaScript is easy to…
#js #redux
action的枚举性质很适合使用es6的
因此在redux的action中请使用字符串,同时在redux中也请尽可能避免使用无法序列化的数据结构
相关讨论
[redux | Action types as symbols](https://github.com/reduxjs/redux/issues/4)
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)
GitHub
Action types as symbols · Issue #4 · reduxjs/redux
Allowing this would be awesome. Why did you enforce type as string? (createDispatcher.js#L67) export const INCREMENT_COUNTER = Symbol() export const DECREMENT_COUNTER = Symbol()
#js trim
js 自带的
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
不要用一个可变的值作为默认值
正确做法
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