Live Note

Remain optimistic

The best investment of the decade turned $1 into $90,000

The decade is almost over — and one incredibly volatile investment stood out from all the rest as the best of the 2010s. Want to guess what it was?

Bitcoin

Read more »

HTML 框架

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<style>
#box {
width: 300px;
height: 300px;
background-color: #ddd;
}
#child {
width: 200px;
height: 100px;
background-color: orange;
}
</style>
<div id="box">
<div id="child">target</div>
</div>
Read more »

config clash.service

file path: /etc/systemd/system

1
2
3
4
5
6
7
8
9
10
11
12
13
[Unit]
Description=Clash service
After=network.target

[Service]
Type=simple
User=edward
ExecStart=/usr/bin/clash -d /home/edward/.config/clash >> /home/edward/.config/clash/clash.log
Restart=on-failure
RestartPreventExitStatus=23

[Install]
WantedBy=multi-user.target
  • start: systemctl start clash
  • stop: systemctl stop clash
  • enable(start when system start): systemctl enable clash
  • disable: systemctl disable clash
  • status: systemctl status clash

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<style>
.container {
width: 200px; /* 固定宽度,触发溢出 */
overflow: hidden; /* 隐藏溢出内容 */
white-space: nowrap; /* 禁止换行 */
}

.text {
display: inline-block;
width: 100%; /* 占满容器 */
direction: rtl; /* 文本方向从右到左 */
text-overflow: ellipsis; /* 显示省略号 */
overflow: hidden;
text-align: left; /* 强制左对齐,保持视觉上的正常阅读方向 */
}
</style>
<div class="container">
<span class="text">短文本不会被省略</span>
</div>

<div class="container">
<span class="text">这是一段很长的文本,左侧会被省略</span>
</div>

e.g.

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
let worker = {
someMethod() {
return 1
},

slow(x) {
console.log("called with " + x)
return x * this.someMethod()
},
}

function decorator(func) {
const cache = new Map()

return function (x) {
if (cache.has(x)) {
console.log("cache hit")
return cache.get(x)
}

const result = func.call(this, x)
cache.set(x, result)

return result
}
}

worker.slow = decorator(worker.slow)

console.log(worker.slow(2))
console.log(worker.slow(2))

Injection

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function injection(func, ...argsBound) {
return function (...args) {
return func.call(this, ...argsBound, ...args)
}
}

// usage
let user = {
firstName: "Edward",
say(time, phrase) {
console.log(`[${time}]: ${this.firstName} ${phrase}`)
},
}

user.say = injection(
user.say,
new Date().getHours() + ":" + new Date().getMinutes()
)

user.say("Hi")

arrow function

1
2
3
4
5
6
7
8
9
10
11
12
function defer(f, ms) {
return function () {
setTimeout(() => f.apply(this, arguments), ms)
}
}

function sayHello(name) {
console.log(`Hi, ${name}`)
}

const deferSay = defer(sayHello, 2000)
deferSay("Edward")

prototype

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
let user = {
name: "Edward",
hello(name) {
console.log(`hi ${this.name}, this is ${name}`)
},
}

Function.prototype.defer = function (ms) {
let f = this
return function (...arg) {
setTimeout(() => f.apply(this, arg), ms)
}
}

user.hello = user.hello.defer(1000)
user.hello("Ejklfj")