Live Note

Remain optimistic

写题时遇见的一个东西

1
2
3
char* s = "hello world";
printf("%15.2s", s);
//result: he

找到如下用法:

  • *%ms:输出的字符串占 m 列,如字符串本身长度大于 m,则突破获 m 的限制,将字符串全部输出。若串长小于 m,则左补空格。
  • *%-ms:如果串长小于 m,则在 m 列范围内,字符串向左靠,右补空格。
  • *%m.ns:输出占 m 列,但只取字符串中左端 n 个字符。这 n 个字符输出在 m 列的右侧,左补空格,注意:如果 n 未指定,默认为 0.
  • *%-m.ns:其中 m、n 含义同上,n 个字符输出在 m 列范围的左侧,右补空格。如果 n>m,则自动取 n 值,即保证 n 个字符正常输出,注意:如果 n 未指定,默认为 0.

如果是 sprintf(desc, “%m.ns”, sour);

  • 如果 desc 空间够的话,会在%m.ns 串 的结尾自动补 null 字符,不同于 strncpy.例如 :sprintf(desc, “%.3s”, “123456”);
  • desc 如果空间>=4 字节的话,第 4 个字节将是 null 字符。

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>

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