0%

Tools -> Developer -> New Snippet…

1
2
3
4
5
6
<snippet>
<content><![CDATA[console.log($1);$0]]></content>
<tabTrigger>log</tabTrigger>
<scope>text.plain,source.js,source.ts</scope>
<description>console.log()</description>
</snippet>

保存为 log.sublime-snippet

使用:

log+回车

npm –save 和–save-dev的区别

使用–save 安装的包是项目发布之后还需要依赖的包, 如axiox , express等包,等项目上线以后还需使用。

使用–save-dev 安装的包则是开发时依赖的包,等项目上线则不会使。

npm install 和 npm i 是一样

–save 和 -S 是一样
–save-dev 和 -D 是一样的

tsc

1
2
3
4
npm i tsc -D
npx tsc --init

npx tsc -w

任何 1.ts 生成 1.js

也可以修改 tsconfig.json 配置

1
2
// "outFile":"./",
// "outDir": "./",

类型

  • boolean

  • number

  • string

  • Explicit

  • Implicit

1
let firstName: string = "Dylan";

unknown 比 any 安全

1
2
3
let w: unknown = 1;

let v: any = true;

date 性能

1
2
3
Date.now()  // 最快
new Date().getTime();
+new Date // 最慢

via https://www.measurethat.net/Benchmarks/Show/9412/0/new-date-vs-new-dategettime-vs-datenow-100k

interface 和 type 区别

  • 接口是通过继承的方式来扩展,类型别名是通过 & 来扩展。
  • 接口可以自动合并,而类型别名不行

https://zhuanlan.zhihu.com/p/351213183

到底应该用 type 还是 interface ?
Because an interface more closely maps how JavaScript objects work by being open to extension, we recommend using an interface over a type alias when possible.
On the other hand, if you can’t express some shape with an interface and you need to use a union or tuple type, type aliases are usually the way to go.

意思是说能用 interface 的地方就用 interface,否则用 type,其实这个解释官方说的也比较明确,这样使用的原因是因为更贴合 JavaScript 对象的工作方式,再清晰一些,如果我们是定义一个 object,那么最好是使用 interface 去做类型声明,什么时候用 type 呢,当定义一个 function 的时候,用 type 会更好一些

1
2
3
4
// the `?` operator here marks parameter `c` as optional
function add(a: number, b: number, c?: number) {
return a + b + (c || 0);
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Person {
private name: string;

public constructor(a: string) {
this.name = a;
}

public getName(): string {
return this.name;
}
}

const person = new Person('david');

console.log(person)

//console.log(person.name)

console.log(person.getName())

class Property ‘’ has no initializer and is not definitely assigned in the constructor

  1. tsconfig.json 关掉严格
1
2
3
"compilerOptions": {
"strictPropertyInitialization":false
}
  1. undefined
1
employees : Employee[] | undefined;
  1. definite assignment assertion
1
employees!: Employee[];
  1. init
1
employees: Employee[] = [];
  1. Assignment in the Constructor

employees: Employee[];

constructor() {
this.employees=[];
}

super

父级构造函数

?? 对比 ||

使用 ?? 时,只有当值1为null或undefined时才返回值2;

使用 || 时,值1会转换为布尔值判断,为true返回值1,false 返回值2

0: Main button pressed, usually the left button or the un-initialized state

1: Auxiliary button pressed, usually the wheel button or the middle button (if present)

2: Secondary button pressed, usually the right button

3: Fourth button, typically the Browser Back button

4: Fifth button, typically the Browser Forward button

下载的美剧是1目录1集,想考出来

a1/a1.mp4
a2/a2.mp4

->

a1.mp4
a2.mp4

1
find . -type f -exec mv {} ./ \;

报错!重名!

a1.mp4/a1.mp4
a2.mp4/a2.mp4

1
find . -type f -exec mv {} ../ \;

那就往上一层(然后删除空目录,再考回去)

hi

数据来源:

https://data.cdc.gov/NCHS/Provisional-COVID-19-Deaths-by-Sex-and-Age/9bhg-hcku

temp1 是第一个 td(Age Group)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var td = $(temp1);
var table = td.closest('table')
var n = td.index()
var rs = []

table.find('tr').each((a,b)=>{
console.log(b)
let td1 = $(b).find('td:eq('+n+')');
let td2 = $(b).find('td:eq('+(n+1)+')');
//console.log(td1,td2)
let t1 = $.trim($(td1).text())
let t2 = $.trim($(td2).text())
console.log(t1,t2)
rs.push({
t:t1,
v:t2
})
})

美国 covid 死亡人数

美国人口 3.319 亿 (2021 年)

从 2020-01-01 到 2022-11-26

  • 各种原因死亡人数: 9,691,052
  • 新冠:1,073,957
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
[
{
"t": "All Ages 各年龄段总数",
"v": "1,073,957"
},
{
"t": "Under 1 year",
"v": "385"
},
{
"t": "0-17 years",
"v": "1,372"
},
{
"t": "1-4 years",
"v": "208"
},
{
"t": "5-14 years",
"v": "428"
},
{
"t": "15-24 years",
"v": "2,858"
},
{
"t": "18-29 years",
"v": "6,688"
},
{
"t": "25-34 years",
"v": "11,870"
},
{
"t": "30-39 years",
"v": "19,136"
},
{
"t": "35-44 years",
"v": "29,076"
},
{
"t": "40-49 years",
"v": "44,856"
},
{
"t": "45-54 years",
"v": "69,339"
},
{
"t": "50-64 years",
"v": "196,036"
},
{
"t": "55-64 years",
"v": "153,924"
},
{
"t": "65-74 years",
"v": "243,622"
},
{
"t": "75-84 years",
"v": "278,544"
},
{
"t": "85 years and over",
"v": "283,703"
}
]
1
2
3
4
5
6
7
let total = rs.reduce((pre,a)=>{    
return a.v.replace(/,/g,'')*1 + pre
},0)

rs.forEach((a)=>{
a.percent = (a.v.replace(/,/g,'')*100/ total).toFixed(3) + '%'
})

对比参考

  • 中国人口:14.12 亿 (2021 年)
  • 2021年 死亡 1014万人 死亡率为7.18‰

  • Vue Theme
  • Night Owl
  • Tokyo Night
  • Sublime Material Theme
  • Synthwave x Fluoromachine
  • Andromeda
  • FireFly Pro
  • One Dark Pro
  • Github Theme
  • Firefox Theme
  • Dracula Official

榜单二

  • One Dark Pro
  • Dracula Official
  • GitHub Theme
  • Winter Is Coming Theme
  • Night Owl
  • Monokai Pro
  • One Monokai
  • Shades of Purple
  • Ayu
  • Palenight
  • Cobalt2 Theme Official
  • SynthWave ‘84
  • Noctis
  • Panda Theme
  • Nord
  • Sublime Material Theme

mac 搜索不到移动硬盘,需要打开 spotlight 索引

/Volumes/AAA 是磁盘名称

打开索引

1
mdutil -i on /Volumes/AAA

重建索引

1
mdutil -E /Volumes/AAA

异常处理

  1. 删除索引
1
sudo mdutil -X /Volumes/AAA
  1. Unmounted硬盘,重新挂接 mount
1
2
3

如果还不开始,开关一下

mdutil -i off /Volumes/AAA
mdutil -i on /Volumes/AAA
```

flex: 1 1 auto;

这是完整写法, 详见mdn, 它还有另外两种完整写法, 分别是 initial (0 1 auto) 和 none (0 0 auto)

第一个参数表示: flex-grow 定义项目的放大比例,默认为0,即如果存在剩余空间,也不放大
第二个参数表示: flex-shrink 定义了项目的缩小比例,默认为1,即如果空间不足,该项目将缩小
第三个参数表示: flex-basis给上面两个属性分配多余空间之前, 计算项目是否有多余空间, 默认值为 auto, 即项目本身的大小

flex-flow 是 flex-direction flex-wrap 快捷方式

flex-flow = flex-direction flex-wrap

google tts mp3

https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=ja&q=料理

1
const url= `https://translate.google.com/translate_tts?ie=UTF-8&tl=${lang}&client=tw-ob&q=${text}`;

电费

333

+150

483 2022-11-19

479.97 2022-11-20

+70

503.13 2022-11-22

478.22 2022-11-23

453.3 2022-11-24

427.39 2022-11-25

398.99 2022-11-26

339.19 2022-11-28

307.80 2022-11-29

190.20 2023-01-02
160.30 2023-01-03

97.85 2023-01-05

+300

229.52 2023-01-11

120.96 2023-01-15

+500

332 2023-01-25

mapbox 笔记

离线
https://cloud.tencent.com/developer/article/1911214?from=article.detail.1604650

mapboxGL2中Terrain的离线化应用
https://cloud.tencent.com/developer/article/1911216?from=15425

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var map = new mapboxgl.Map({
container: 'map',
style: 'https://www.example.com/styles/streets/style.json',
center: [53.33, 24.5],
zoom: 8,
transformRequest: function(url, resourceType) {
if(resourceType !== 'Tile') {
return {
url: url,
};
}

return axios.get('../api/get-token.php', {
params: {
AccessURL: url
},
headers: {
'X-Requested-With': 'XmlHttpRequest'
}
}).then(function (response) {
return {
url: url,
headers: {
'X-Requested-With': 'XmlHttpRequest'
'token': response.data.token
}
}
});
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var map = new mapboxgl.Map({
container: 'map',
style: 'https://www.example.com/styles/streets/style.json',
center: [53.33, 24.5],
zoom: 8,
transformRequest: async function(url, resourceType) {
if(resourceType !== 'Tile') {
return {
url: url,
};
}

try {
const response = await axios.get('../api/get-token.php', {
params: {
AccessURL: url
},
headers: {
'X-Requested-With': 'XmlHttpRequest'
}
});
return {
url: url,
headers: {
'X-Requested-With': 'XmlHttpRequest'
'token': response.data.token
}
};
} catch (error) {
return {
url: url,
};
}
}
});

查看 shell 代码

忘记 proxy 命令写在哪里了 :(

1
type -a proxy

代码 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var map = map||test||test.map;
var mytest = function(e){
// console.log(e)
let map = test
let fs = map.queryRenderedFeatures(
e.point,
{
layers: ['layer_goudao']
}
);
// console.log(fs)
func_draw_pp(fs)

}
mytest && map.off('click',mytest)
map.on('click',mytest)
map.setPitch(60)

function func_draw_pp(fs){
let rs = []
fs.forEach(a=>{
console.log(a)
let line = turf.lineString(a.geometry.coordinates);
console.log(line)
let along = turf.along(line,0.1)
rs.push(line)
rs.push(along)
})

map.getSource('temp_line').setData({
type:'FeatureCollection',
features:rs
})
}

代码 2

1
2
3
let fs = map.queryRenderedFeatures({layers: ['layer_goudao'] } );
console.log(fs)

1
2
3
4
5
turf.lineString(temp1[0].geometry.)


map.getSource('temp_line').setData()

turf.lineString([[108.97049293140219,34.33153377857526],[109.02010306934216,34.332029922789474] ])

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
var map = map||test||test.map;
var mytest = function(e){
//console.log(e)
let map = test
let fs = map.queryRenderedFeatures(
e.point,

{
layers: ['layer_goudao']
}
);
console.log(fs)

}
mytest && test.off('click',mytest)
test.on('click',mytest)
map.setPitch(60)

let rs = []
temp1.forEach(a=>{
console.log(a)
let line = turf.lineString(a.geometry.coordinates);
console.log(line)
rs.push(line)

map.getSource('temp_line').setData(line)

})

map.getSource(‘temp_line’).setData({
type:’FeatureCollection’,
features:rs
})

1
2
test.off('click',mytest)
test.on('click',mytest)
1

https://www.samanthaming.com/journal/3-how-to-use-lodash-with-vue/

slice 复制 比 loop 快

1
2
3
4
5
6
7
n = 1000*1000;
start = + new Date(); // A=+B 会进行 B转化为数字 赋值给A
a = Array(n);
b = Array(n);
i = a.length;
while(i--) b[i] = a[i];
console.log(new Date() - start);
1
2
3
4
5
n = 1000*1000;
start = + new Date();
a = Array(n);
b = a.slice();
console.log(new Date() - start);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const cityCoordinates = [
[100.507, 13.745],
[98.993, 18.793],
[99.838, 19.924],
[102.812, 17.408],
[100.458, 7.001],
[100.905, 12.935]
];
const map = new mapboxgl.Map({
container: 'map',
// Choose from Mapbox's core styles, or make your own style with Mapbox Studio
style: 'mapbox://styles/mapbox/streets-v12',
center: [100.507, 13.745],
zoom: 9
});

map.on('load', () => {
for (const [index, coordinate] of cityCoordinates.entries()) {
setTimeout(() => {
map.jumpTo({ center: coordinate });
}, 2000 * index);
}
});

for in 和 for of 区别

https://kanboo.github.io/2018/01/30/JS-for-of-forin/

update feature in realtime

https://docs.mapbox.com/mapbox-gl-js/example/live-update-feature/

2023年推荐书目(吴尔夫)
1.《生活与命运》(俄罗斯),瓦西里.格罗斯曼。力冈译
2.《枪炮、病菌与钢铁一一人类社会的命运》(美)贾雷德.戴蒙德〈扩展阅读:《崩溃:社会如何选择成败兴亡》;《第三和猩猩一一人类的身世与未来》),《剧变》等),谢延光译
3.《文明的冲突与世界秩序的重建》(美)塞缪尔.享廷顿,周琪等译
4.《演化的故事:40亿年生命之旅》(美)卡尔.齐默
5.《透过地理看历史》,李不白

给我们读书会的2023年推荐这几本书:

  1. 《鼠疫》法国.阿尔贝·加缪
  2. 《陆犯焉识》美国.严家苓
  3. 《可能性的艺术:比较政治学30讲》中国.刘瑜
  4. 《大明王朝的七张面孔》中国.张宏杰