Live Note

Remain optimistic

为什么需要无线调试

方便
无线调试可以让你在手机上进行调试,而不用连接电脑,可以节省时间。

这几天尝试使用无限调试,但是总是会有 bug,adb 死机,手机重启,导致调试失败。

1
2
# 使用 adb 6未数字码方式 连接手机
adb pair 192.168.1.100

在 Mac 下,我的手机只能成功连接一次,后续就再也连不上了

无奈,只能使用 Android Studios 调试。

  1. 使用 Android Studios 插件:ADB WI-FI
  2. USB 连接手机
  3. 打开 ADB WI-FI 面板
  4. 自动连接

这种方式目前比较稳定,可以成功连接手机,并且可以进行调试,并且每次启动都可以重新成功连接。

Update at 2025 年 03 月 10 日 16:33:15

pair 成功后, 在无线 adb 里面开启, 然后直接adb connect 192.168.1.100:5555即可连接。

起因

许久未使用mac,然后发现在terminal里使用code <name>的时候,报错了。

1
2
/usr/local/bin/code: line 6: /usr/bin/python: No such file or directory
/usr/local/bin/code: line 10: ./MacOS/Electron: No such file or directory

后面才发现,系统里只有python3,没有python,遂在/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code中将python修改为python3得以解决。

ES6 提供了 Map 数据结构,它类似对象,也是键值对的集合,但是‘键’的范围不限于字符串,各种类型的值(包括对象)都可以当做键。Map 结构是一种更完善的 Hash 结构实现。如果需要‘键值对’的数据结构,Map 比 Object 更合适。

1
2
3
4
let m = new Map()
const o = { p: "hello" }
m.set(o, "content")
m.get(o) //'content'

Map 也可以接受一个数组作为参数,该数组的成员是一个表示键值对的数组:

1
2
3
4
5
6
7
8
const map = new Map([
["name", "张三"],
["title", "test"],
])

map.size //2
map.has("name") //true
map.get("name") //'张三'

Map 构造函数接受数组作为参数,实际上执行的是下面的算法:

1
2
3
4
5
6
const item = [
["name", "张三"],
["title", "test"],
]
const map = new Map()
item.forEach(([key, valule]) => map.set(key, value))
Read more »

Math.trunc()

Math.trunc 用于除去一个数的小数部分。

1
2
3
4
5
6
7
8
9
10
11
Math.trunc(111.22) //111
Math.trunc("123.456") //123
//对空和无法截取整数的值,返回 NaN
Math.trunc(NaN) //NaN

//代码模拟
Math.trunc =
Math.trunc ||
function (x) {
return x < 0 ? Math.ceil(x) : Math.floor(x)
}
Read more »

Mix-ins

Abstract subclasses or mix-ins are templates for classes. An ECMAScript class can only have a single superclass, so multiple inheritance from tooling classes, for example, is not possible. The functionality must be provided by the superclass.

eg:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const calculatorMixin = (Base) =>
class extends Base {
calc() {
// do something
}
}

const randomizerMixin = (Base) =>
class extends Base {
remdomize() {
// do something
}
}

class Foo {}
class Bar extends calculatorMixin(randomizerMixin(Foo)) {}
const bar = new Bar()
console.log(bar.calc)
console.log(bar.remdomize) // also a function.