分類
說說

230829

我現在住到的地方可以買到本地產的青皮蕉,酸酸甜甜非常好吃又便宜。但是香蕉皮放在垃圾桶裏,不用半天就會引來小果蠅。雖然我家裝有沙窗,但是果蠅太小,可以穿網而過。小陽臺的角落裏放着我家的小小堆肥箱,底部是一些土,上面用來放咖啡渣和茶葉渣。最近從山上移栽了一棵艾草回來,不僅順利成活並且長勢喜人。

昨晚聽到壁虎叫的很大聲,今天早上一看,一個可愛的小壁虎從堆肥箱後面探出頭來吃果蠅。前段時間廚房也出現了蜘蛛了來吃果蠅,但是蜘蛛會在牆角留下一些一毫米左右的小黑屎,增加了 Emanon 的家務。

分類
软件

Paseo 步數記錄軟件

散步是人生中的大事,而 Paseo 可以記錄與督促它。祝大家都有一個健康的體魄。

上個月,F-Droid 被 DNS 污染,這個月遭遇不同程度屏蔽。

分類
程序

免費使用 AWS Lambda 的一個示例

這裏演示一下免費使用 AWS Lambda 創建一個查詢網頁大小的接口。之所以直接使用 Lambda 生成的鏈接而不是 API Gateway 的鏈接,是因爲 API Gateway 的免費額度是在註冊帳號的一年內有效。而且 API Gateway 最大超時只有 30 秒,而 Lambda 可以設置到 15 分鐘。

首先註冊一個帳號,我記得只要郵箱和手機號就行,不用綁定支付方式。然後在控制台搜索 Lambda 進入 Lambda 控制台。點擊 Funtction > Create function. 選擇 Author from scratch,輸入函數名字沒有特殊要求,Runtime 選 Python 3.10,Architecture 選 x86 和 arm64 都可以,各有免費額度。點開 Advanced settings,勾選 Enable function URL,勾選 None。CORS 看需要也可以勾上,然後點擊右下角 Create function 就可以了。

在函數頁面 Code 標籤頁貼上如下代碼:

import json
import os
import random
import urllib.request

UA = '''Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edge/19041.423
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 OPR/87.0.4390.99
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Vivaldi/6.1.3035.111
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:85.0) Gecko/20100101 Firefox/85.0
Mozilla/5.0 (Windows NT 10.0; Win64; x64; Trident/7.0; rv:11.0) like Gecko
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.51 Safari/537.36
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36'''

US_LIST=UA.split()

def lambda_handler(event, context):
    event_body_str = event['body']
    event_body = json.loads(event_body_str)
    # print(str(event_body))
    if event_body['secret'] == os.environ.get('secret'):
        try:
            t_ua = random.choice(US_LIST)
            res = urllib.request.urlopen(urllib.request.Request(
                url=event_body['url'],
                headers={"User-Agent": t_ua,},
                method='GET'),
                timeout=180)
            content = res.read()
            return {
                'statusCode': 200,
                'body': json.dumps(str(len(content))+' '+event_body['url'])
            }
        except:
            return {
                'statusCode': 500,
                'body': json.dumps('request failed.')
            }
    else:
        return {
            'statusCode': 500,
            'body': json.dumps('unauthorized.')
        }

secret 的環境在 Configuration > Environment variables 中添加。在 General configuration 中可以設置函數的超時時長 Timeout,默認是 3 秒。在 Function URL 裏可以看到我們需要的 URL 類似:https://4xyqiuexi7l3fcnuyuevjgclei0jhpuy.lambda-url.us-east-1.on.aws/ 。使用如下 curl 命令測試下:

curl -X POST -H "Content-Type: application/json" -d '{"secret":"Dn2Xk7d7RDkK_8bILy7lVe2NJlE4y7T_", "url":"http://ip-api.com/json"}' https://4xyqiuexi7l3fcnuyuevjgclei0jhpuy.lambda-url.us-east-1.on.aws/
#應該會得到如下結果
"296 http://ip-api.com/json"

免費額度使用情況可以在 Billing > Free Tier 頁面查看。Lambda 服務每月有 400000 seconds(GB-Second,如果的函數和我的一樣用的是 128 MB,那就可以乘以 8)和 1000000 次請求。

分類
其它

中國移動用戶不要購買AU索尼手機

時間來到 2023 年,國內的二手機市場也迎來了新一代的索尼手機,其中 1、5、10 系列都各有所長。唯一需要注意的就是 AU 的手機對於中國移動用戶來說缺少的頻段過多,輕則導致上網不暢,重則漏接電話短信,除非你只是連 Wi-Fi。而 Docomo 雖然也缺一個移動頻段,但是日常使用中並不影響。關於二手索尼的版本,我推薦的順序是港版(雙卡雙待可刷機) > 歐版(可刷機) > Docomo日版 > Au日版。 當然市場價格應該也是這個順序。

分類
Linux

Fedora 35 失去支持後升級 37

Fedora 失去支持後

失去支持後,dnf upgrade 會報錯 "Failed to download metadata for repo 'updates'" 。可以修改 /etc/yum.repos.d/ 中如下四個文件:fedora.repo fedora-modular.repo fedora-updates.repo fedora-updates-modular.repo 中的兩行

baseurl=https://archives.fedoraproject.org/pub/archive/fedora/linux/updates/$releasever/Everything/$basearch/
#metalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch

修改後便不再報錯,但是由於 35 已失去官方支持,所以不會再有更新。

升級 Fedora 系統

!畢竟是更新系統,所以重要資料記得備份。!

可以通過 dnf system-upgrade 來方便的升級到 36 或 37(但是不能直接升級到38)。升級系統請參考官方的 DNF System Upgrade 以及 Upgrade to Fedora 37 from Fedora 36 using DNF。大約要下載 2G 大小的文件,下載後升級過程需要半個小時左右。主要命令如下:

#更新一下,如果有更新之後要重啓一下
sudo dnf upgrade --refresh
#安裝系統升級 dnf 插件
sudo dnf install dnf-plugin-system-upgrade
#下載要升級到的版本,如 37
sudo dnf system-upgrade download --releasever=37
#下載完畢,執行系統更新
sudo dnf system-upgrade reboot

執行 system-upgrade download 前需要把前面四個文件改回去,不然 archive 站點是沒有新系統的資料包的。

分類
程序

在 VS Code 中調試 Django Q 任務

在 .vscode 文件夾中創建一個 lanch.json 文件, 內容如下:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Django Q",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/manage.py",
            "args": [
                "qcluster"
            ],
            "django": true,
            "env": {
                "DJANGO_SETTINGS_MODULE": "YOUR_PROJECT_NAME.settings"
            },
            "gevent": true
        },
        // Your other configurations go here
    ]
}

只需修改兩個地方:program 裏的 ${workspaceFolder} 是變量,如果你項目的 manage.py 在 VS Code 項目根目錄下,那這行就不用修改。 DJANGO_SETTINGS_MODULE 這裏需要把 YOUR_PROJECT_NAME 替換成你項目的名字。然後按 Debug 按鈕就可以調試 Django Q task 了。

對於這個問題,ChatGPT 4 前前後後給出了五次錯誤配置,不得不記錄一下。

分類
方法

Bislama introduction from Air Vanuatu

In the late 19th century at the height of the practice of Blackbirding, thousands of Ni-Vanuatu were forced to work on plantations in Australia and Fiji. With several languages being spoken in these plantations, a form of pidgin English was developed, combining English vocabulary with grammatical structures typical of languages in the region. This early plantation pidgin is the origin not only of Bislama, but also of Tok Pisin of Papua New Guinea and Pijin of the Solomon Islands.

This pidgin started spreading over the Vanuatu archipelago at the turn of the 20th century, as the survivors of Blackbirding began to come back to their native islands. Knowledge of this pidgin would facilitate communication not only with European traders and settlers, but also between native populations of remote islands within the archipelago.

Ni-Vanuatu began to add their own words and pronunciation (today 95% of Bislama is based on English, with a few dozen French words and ‘island language’ thrown in).

Over the past century or so, Bislama has evolved to what is currently spoken and written in Vanuatu.

In order to understand Bislama, common advice is to throw in the words "long" and "blong" a few times every sentence and you'll just about have It.

For example,

Stoa kolosap long haos: The store next to the house.

Mi bin stap long ples ia bifo: I have stayed at this place before. Breakdown of the sentence:
- "Mi" means "I"
- "bin" is a past tense marker, indicating that the action happened in the past.
- "stap" means "staying" or "living."
- "long" is a preposition that means "in" or "at."
- "ples" means "place."
- "ia" is a demonstrative marker that can mean "this" or "that" depending on the context.
- "bifo" means "before" or "previously."

Mi stap long stoa: I am at the store.

Jea long haos: The chair in the house.

Buk blong mi: The book that belongs to me, my book

Man Amerika: Man from America, American.

Hemi woman blong saiens: She is a woman of science, she is a scientist.

Here's a few other phrases to get you going on your journey to discovering this fascinating and fun new language.

  • How much is that? Hamas long hem?
  • How much is this? Hamas long hemia?
  • Do you know..? Yu save (pronounced savvy)
  • I don’t know. Mi no save
  • This is broken Samting ia hemi bugarup or Samting ia i brok
  • The best Nambawan
  • How are you? Olsem wanem
  • I'm okay la oreat
  • Water Wota
  • Drinking water Freswota
  • Ocean Solwota
  • Full / too much Fulap
  • Thank you Tankyu
  • Thank you very much Tankyu tumas
  • My name is... Nem blong mi
  • What time does the plane land? Wanem taem plen ia lan?
  • Food/eat Kai Kai
  • Dictionary Diksonari

本文更新於 2023/02/20。