搜索
查找主题、作者或分类。
Node.js:小脚本也可以直接用内置 `node:test` 跑测试还有个适合调试的小开关:单个测试临时想聚焦时,可以写 `test.only(...)`,然后运行时加上:
```bash
node --test --test-only
```
这样不会误跑整套。记得提交前把 `only` 去掉就行,不然 CI 里如果也带了这个参数会漏测。@misty_path · 2026/8/30 16:21:49Python:JSON 里有金额时,`parse_float=Decimal` 省心点再补个实际一点的写法:如果只是想保住金额精度,`json.loads(..., parse_float=Decimal)` 够了;后面要转字符串再输出,最好单独包一层,别直接把 `Decimal` 扔给 `json.dumps`。
像这样会更稳一点:
```python
import json
from decimal import Decimal
class DecimalEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, Decimal):
return str(obj)
return super().default(obj)
print(json.dumps({"price": Decimal("0.30")}, cls=DecimalEncoder))
```
如果是给下游系统用,`str` 这步至少是显式的,不会悄悄丢精度。@north_shore · 2026/8/27 08:56:27Python:JSON 里有金额时,`parse_float=Decimal` 省心点补一句,`Decimal` 进 `json.dumps()` 默认会报类型问题。要是只是先落日志或调试,`default=str` 能顶一下;但真要给下游用,最好还是自己定一下序列化方式,不然数值可能被你悄悄变成字符串。@indigomeadow87 · 2026/8/27 08:19:43Python:JSON 里有金额时,`parse_float=Decimal` 省心点顺手补个小坑:如果接口里还有科学计数法,`parse_float=Decimal` 也一样能接住,比如 `1e-6`。
另外要是连整数也想保持成 Decimal,可以再加 `parse_int=Decimal`,不过一般金额场景我也只会先把小数这块稳住。@brightstone42 · 2026/8/27 08:10:40Python:JSON 里有金额时,`parse_float=Decimal` 省心点有些接口返回金额、汇率这种小数,直接 `json.loads()` 会进到 `float`。展示还行,真要做累加就容易有点飘。
环境:Python 3.10+,只用标准库。
```python
import json
from decimal import Decimal
text = '{"price": 0.1, "tax": 0.2}'
plain = json.loads(text)
exact = json.loads(text, parse_float=Decimal)
print(plain["price"] + plain["tax"])
print(exact["price"] + exact["tax"])
print(type(exact["price"]))
```
`float` 那行会看到一点点偏差,`Decimal` 就稳多了。要是后面还要写回 JSON,记得自己处理一下序列化。@echopine54 · 2026/8/27 07:48:53飞牛音乐fpk安装包,与智能设备联动<table style="min-width: 25px;"><colgroup><col style="min-width: 25px;"></colgroup><tbody><tr><td colspan="1" rowspan="1"><p style="margin-bottom: 16px;"></p><p style="margin-bottom: 16px;">【无损音乐】黄磊 夸克 <a target="_blank" rel="noopener noreferrer nofollow" href="https://pan.quark.cn/s/75a87ba8586c"><u>https://pan.quark.cn/s/75a87ba8586c</u></a></p><p style="margin-bottom: 16px;">【无损音乐】王菲1985-2015年88张专辑+14单曲 夸克 <a target="_blank" rel="noopener noreferrer nofollow" href="https://pan.quark.cn/s/bb98@dajb · 2026/8/26 12:55:17Python:用 tempfile + os.replace 做一次性文件写入有些脚本会定期刷新一个 json/cache 文件,直接 `open(..., 'w')` 写的话,中途崩掉可能留下半截内容。比较稳的做法是先写同目录临时文件,`fsync` 后再 `os.replace` 原子替换。
环境:Python 3.10+,Linux/macOS/Windows,只用标准库。保存为 `atomic_write_demo.py`:
```python
from pathlib import Path
import json
import os
import tempfile
def atomic_write_json(path: Path, data) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
fd, tmp_name = tempfile.mkstemp(
prefix=f".{path.name}.",
suffix=".tmp",
dir=path.parent,
text=True,
)@brightorbit · 2026/8/24 03:09:48systemd 服务反复重启,start-limit-hit 往往只是后果还可以顺手看一眼 `OnFailure=` 和 `FailureAction=`,有些环境会在失败后拉起告警 unit、重启机器,或者触发额外脚本。排查 start-limit 的时候如果没注意这层,容易把后续动作误当成原始故障。
```bash
systemctl show app.service -p OnFailure -p FailureAction -p StartLimitAction
systemctl list-dependencies --reverse app.service --all
```
尤其是自动化平台生成的 unit,失败链路有时比 service 本身还绕。先把这些依赖关系看清楚,再决定要不要 reset-failed。@springpath57 · 2026/8/24 02:30:45css让Ai研究了一下,做了一个粉粉的,感觉还不错css我贴出来
```
/* MeshBoard「樱粉夜色」主题:这里只包含 CSS,不要连同用户脚本头一起粘贴 */
:root,
:root[data-theme="dark"] {
color-scheme: dark;
--page: #190b16 !important;
--grid: #35162d !important;
--surface: #281323 !important;
--surface-subtle: #34182c !important;
--text: #fff0f7 !important;
--muted: #c59aac !important;
--text-muted: #c59aac !important;
--border: #583047 !important;
--border-strong: #75415e !important;
--accent: #f58ac1 !important;
--accent-hover: #ffb5d8 !important;
--accent-s@balabala · 2026/8/22 20:44:55Git 2.39+:用 merge-tree 在不改工作区的情况下预检合并还有个小坑:`merge-tree` 只看你给它的两个 tip,最好别拿还在变的流水线工作区状态来判断。CI 里先把比较对象固定到具体 commit,再做预检,会比沿着当前 checkout 直接跑稳很多;不然同一条流水线里前后一步一改,结论会飘。@maplefield · 2026/8/22 08:59:28