分類
其它

小磁鐵拯救 Kindle 電源鍵

我有一個 Kindle Paperwhite (7th generaton),使用很多年後電源鍵逐漸凹陷,現在喚醒越來越困難。搜索後發現可以買一個 Kindle 翻蓋保護套,保護套一般會內置一塊小磁鐵與 Kindle 右下角的磁場傳感器感應實現喚醒與關閉。然後我發現之前從廢棄耳機裏拆出來的小磁鐵也可以喚醒 Kindle,立省 20 塊。

分類
說說

260818

In an unfree country, whenever you spark an interesting idea—be it commercial or charitable, for-profit or non-profit, individual or collective, selfish or altruistic—a careful look at the policies will likely reveal that it is already illegal.

在失去自由的土壤裡,任何一顆有趣的種子都難以見光。當你產生一個絕妙的構想,無論它是出於商業或公益,是為己還是為人,只要對著條文細細審視,便會無奈地發現:它早已被定義為非法。

我熱愛自然,但受限於《中華人民共和國自然保護區條例》

分類
程序

一個簡單的 base64 轉換

在本地瀏覽器中使用 JavaScript 完成轉換,源碼在下面:

function encodeBase64() {
    const input = document.getElementById('base64-input').value;
    const output = document.getElementById('base64-output');

    if (!input) {
        output.value = '';
        return;
    }

    try {
        // UTF-8 text → Base64
        const bytes = new TextEncoder().encode(input);

        let binary = '';
        bytes.forEach(byte => {
            binary += String.fromCharCode(byte);
        });

        output.value = btoa(binary);

    } catch (error) {
        output.value = 'Error: Unable to encode the text.';
    }
}


function decodeBase64() {
    const input = document.getElementById('base64-input').value.trim();
    const output = document.getElementById('base64-output');

    if (!input) {
        output.value = '';
        return;
    }

    try {
        // Base64 → binary
        const binary = atob(input);

        // Binary → UTF-8 text
        const bytes = Uint8Array.from(
            binary,
            char => char.charCodeAt(0)
        );

        output.value = new TextDecoder('utf-8').decode(bytes);

    } catch (error) {
        output.value = 'Error: Invalid Base64 data.';
    }
}


function copyBase64() {
    const output = document.getElementById('base64-output');

    if (!output.value) {
        return;
    }

    navigator.clipboard.writeText(output.value).then(() => {
        alert('Result copied to clipboard.');
    }).catch(() => {
        output.select();
        document.execCommand('copy');
        alert('Result copied to clipboard.');
    });
}


function clearBase64() {
    document.getElementById('base64-input').value = '';
    document.getElementById('base64-output').value = '';
}
分類
陰陽怪氣

260812

掃黑除惡,守護你我平安。黨中央部署開展爲期一年的深化掃黑除惡專項鬥爭,依法懲處涉黑涉惡違法犯罪,保障人民安居樂業、社會安定有序、國家長治久安。廣大羣衆可以通過全國掃黑辦12337舉報平臺等多種方式舉報黑惡犯罪。全國掃黑除惡專項鬥爭領導小組

分類
Linux

在 Xfce 的狀態欄顯示網速

理想情況下,如果要在 Xfce 的狀態欄(Panel)顯示網速,只需要在狀態欄新增項目,選擇自帶的 Network Monitor 就可以了。但是某次升級內核後(5.14.0),/proc/net/dev 就不在有網速數據,導致從那裏讀取網速的 Network Monitor 和 vnstat 都無法工作。vnstat 可以統計過往流量的數據,不過也可以在路由器上查看,所以就先不管了。狀態欄的實時網速則可以通過下面的 Python 腳本來顯示。

#安裝依賴
sudo dnf install xfce4-genmon-plugin python3-gobject gtk3
#測試依賴
/usr/bin/python3 -c "import gi; print('PyGObject OK')"
#確認網絡數據
ethtool -S wlp1s0 | grep -E 'rx_bytes|tx_bytes'

#新建腳本目錄
mkdir -p ~/.local/bin ~/.cache/wifi-netload
nano ~/.local/bin/wifi-netload.py
#!/usr/bin/python3

import os
import re
import time
import subprocess

INTERFACE = "wlp1s0"

CACHE_DIR = os.path.expanduser("~/.cache/wifi-netload")
CACHE_FILE = os.path.join(CACHE_DIR, "counters")

os.makedirs(CACHE_DIR, exist_ok=True)


def get_counters():
    try:
        result = subprocess.run(
            ["/usr/sbin/ethtool", "-S", INTERFACE],
            capture_output=True,
            text=True,
            timeout=2,
            check=True,
        )

        rx_match = re.search(
            r"^\s*rx_bytes:\s*(\d+)",
            result.stdout,
            re.MULTILINE,
        )

        tx_match = re.search(
            r"^\s*tx_bytes:\s*(\d+)",
            result.stdout,
            re.MULTILINE,
        )

        if not rx_match or not tx_match:
            return None

        return int(rx_match.group(1)), int(tx_match.group(1))

    except (subprocess.SubprocessError, OSError, ValueError):
        return None


def format_rate(bytes_per_second):
    """Format speed using fixed-width decimal units."""

    kb = bytes_per_second / 1000

    if kb < 1000:
        return f"{kb:6.1f} K"

    mb = kb / 1000
    return f"{mb:6.2f} M"


def load_previous():
    try:
        with open(CACHE_FILE, "r") as f:
            parts = f.read().split()

        if len(parts) != 3:
            return None

        return (
            int(parts[0]),
            int(parts[1]),
            float(parts[2]),
        )

    except (OSError, ValueError):
        return None


def save_current(rx, tx):
    try:
        tmp = CACHE_FILE + ".tmp"

        with open(tmp, "w") as f:
            f.write(f"{rx} {tx} {time.monotonic()}\n")

        os.replace(tmp, CACHE_FILE)

    except OSError:
        pass


def main():
    current = get_counters()

    if current is None:
        print("0.0 KB/s  0.0 KB/s")
        return

    rx, tx = current
    previous = load_previous()

    save_current(rx, tx)

    if previous is None:
        print("0.0 KB/s  0.0 KB/s")
        return

    old_rx, old_tx, old_time = previous

    elapsed = time.monotonic() - old_time

    if elapsed <= 0:
        print("0.0 KB/s  0.0 KB/s")
        return

    # Handle counter resets.
    rx_delta = max(0, rx - old_rx)
    tx_delta = max(0, tx - old_tx)

    rx_rate = rx_delta / elapsed
    tx_rate = tx_delta / elapsed

    print(
        f"{format_rate(rx_rate)} "
        f"{format_rate(tx_rate)}"
    )


if __name__ == "__main__":
    main()

chmod +x ~/.local/bin/wifi-netload.py
#手動執行
~/.local/bin/wifi-netload.py
#應該顯示出類似   1.55 M   24.2 K

最後在 Xfce 狀態欄添加項目,選擇 Generic Monitor。命令欄填 /home/42/.local/bin/wifi-netload.py, 刷新頻率選 1,字體需要選一個等寬字體,不然網絡變動時會一跳一跳的,比如 Source Code Pro Bold 10。這樣就又能在狀態欄看見實時網速了。

分類
說說

260727

由於住宅區民宿設施因噪音及垃圾處理等頻繁引起糾紛,日本觀光廳已向全國各地方政府發出通知,允許其透過修改條例實質上禁止民宿營業。

自2018年《民泊新法》開始實施以來,在住宅區經營民宿得以解禁。伴隨外國旅客的增加,民宿市場急劇擴大,然而與此同時,因噪音和垃圾處理等引發的社區糾紛也不斷發生。

為此,觀光廳於7月15日向全國各地方政府發出通知,允許其可透過修改地方條例,將法律所規定的民宿營業天數每年最長「180天」的上限設定為「0天」。

——NHK:《日本觀光廳允許地方政府實質上禁止民宿營業》

剛剛被樓下鄰居和小孩高聲叫喊氣到的我去下載了《醜陋的中國人》。如果你也要讀,建議讀臺灣原版,因爲大陸版有刪減。

分類
說說

揭陽

我從來沒有去過揭陽,但是兩三年前旅行時發現廣東西部的幾個城市吃狗肉的風氣很重,「脆皮狗」的招牌很多。

之前在內地旅行,候機時不時能看到飛揭陽的航班,心想揭陽發展挺好的,最近一次有這個印象是從新加坡回來,也看到飛揭陽的航班。

我住的的地方有不少揭陽人,所以我吃過揭西擂茶。擂茶非常有特色,大概是把綠茶磨碎加入大米花、花生和青菜的湯。她們做的客家早餐和炒粉也都很好吃。

家裏辦理的廉價寬帶,出口 IP 到處飄,而且經常被豆瓣、Bilibili、淘寶等網站攔截,比如今天的 IP 就是揭陽的。

curl ip9.com.cn | jq
{
  "ret": 200,
  "data": {
    "ip": "120.240.*.*",
    "country": "中国",
    "country_code": "cn",
    "prov": "广东",
    "city": "揭阳",
    "city_code": "jieyang",
    "city_short_code": "jy",
    "area": "",
    "post_code": "522000",
    "area_code": "0663",
    "isp": "中国移动",
    "lng": "116.355733",
    "lat": "23.543778",
    "long_ip": 0,
    "big_area": "华南"
  },
  "qt": 0
}

當我跟 Emanon 說起揭陽虐狗事件時,她想到了馬幫的這首《黃楊扁擔》,其實跟揭陽和狗都沒有關係。話說回來,廣西也是吃狗大省,愿它們來世可以去格魯吉亞、土耳其、印度或者任何對流浪狗友好的世界。

(調小聲音先)