cat-catch 设置 N_m3u8DL-RE

ref https://github.com/nilaoda/N_m3u8DL-RE
ref https://github.com/xifangczy/cat-catch
ref https://github.com/corbamico/m3u8dl-invoke/

1.1 安装 n-m3u8dl-re

1
scoop install n-m3u8dl-re_x

1.2 新建 m3u8dl 程序

先用 powershell 写一段脚本 n_m3u8dl-re_protocol.ps1 ,然后转换成可执行文件 n_m3u8dl-re_protocol.exe

  • 脚本
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    # 接收m3u8://xxxxxx
    param($m3u8url)
    Write-Host "m3u8url: $m3u8url"

    $bs64 = $m3u8url.replace('m3u8dl://', '').replace('/', '')
    $httpurl = [Text.Encoding]::ASCII.GetString([Convert]::FromBase64String($bs64))
    Write-Host "httpurl: $httpurl"

    $path = 'c:\Users\xxxxx\scoop\shims\N_m3u8DL-re.exe'
    $cmd = $path + ' ' + $httpurl
    Write-Host "$cmd"

    Start-Process "$path" "$httpurl" -NoNewWindow
    Start-Sleep 30
  • 转换
    1
    2
    3
    Install-Module ps2exe

    ps2exe n_m3u8dl-re_protocol.ps1 n_m3u8dl-re_protocol.exe
阅读全文 »

matplotlib marker color 字符对照

ref: https://matplotlib.org/stable/api/colors_api.html
ref: https://matplotlib.org/stable/gallery/color/named_colors.html

1
2
3
4
5
6
7
8
9
10
11

import matplotlib.pyplot as plt
import matplotlib.colors as mcolors

for (k, v) in mcolors.BASE_COLORS.items():
v = "#" + "".join(format(round(val * 255), "02x") for val in v)
print(f'<font color="{v}"> {k:<10} ■ </font>')

for (k, v) in mcolors.TABLEAU_COLORS.items():
print(f'<font color="{v}"> {k:<10} ■ </font>')

mcolors.BASE_COLORS (8)

████ b
████ g
████ r
████ c
████ m
████ y
████ k
████ w

BASE_COLORS

mcolors.TABLEAU_COLORS (10)

████ tab:blue
████ tab:orange
████ tab:green
████ tab:red
████ tab:purple
████ tab:brown
████ tab:pink
████ tab:gray
████ tab:olive
████ tab:cyan

阅读全文 »

matplotlib marker 类型字符对照

ref: https://matplotlib.org/stable/api/markers_api.html
ref: https://matplotlib.org/stable/gallery/lines_bars_and_markers/marker_reference.html#sphx-glr-gallery-lines-bars-and-markers-marker-reference-py

1
2
3
4
5
6

unfilled_markers = (',', '1', '2', '3', '4', '+', 'x', '|', '_')
unfilled_markers = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) # int
filled_markers = ('.', 'o', 'v', '^', '<', '>', '8', 's', 'p', '*', 'h', 'H', 'D', 'd', 'P', 'X')


阅读全文 »

文件夹禁用文件类型识别

文件夹启动时默认会识别该文件夹内的文件类型(比如图片、音乐、视频等媒体文件的信息),媒体文件过多时加载速度较慢。

可以禁用此功能。

1
2
3
4
5
6
# 管理员运行运行后重启:
reg add "HKCU\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags\AllFolders\Shell" /v "FolderType" /t REG_SZ /d "NotSpecified" /f

# 恢复默认:
# reg.exe delete "HKCU\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags\AllFolders\Shell" /f

Python f-string 备忘单

ref https://fstring.help/cheat/

ref https://cheatography.com/brianallan/cheat-sheets/python-f-strings-basics/
ref https://cheatography.com/brianallan/cheat-sheets/python-f-strings-number-formatting/

数字

num format
%d 整数
%e 科学计数
%f 浮点
% 百分数
%b 二进制
%o 八进制
%x 十六进制
%c Unicode

integer = 123
number_ = 9876.6789
percent = 0.98765

var num format f-string output
integer 123 d f’{integer:d}’ 123
integer 123 b f’{integer:b}’ 1111011
integer 123 8b f’{integer:8b}’ 1111011
integer 123 _b f’{integer:_b}’ 111_1011
integer 123 09_b f’{integer:09_b}’ 0111_1011
integer 123 o f’{integer:o}’ 173
integer 123 #o f’{integer:#o}’ 0o173
integer 123 x f’{integer:x}’ 7b
integer 123 #x f’{integer:#x}’ 0x7b
integer 123 08x f’{integer:08x}’ 0000007b
integer 123 c f’{integer:c}’ {
number_ 9876.6789 f f’{number_:f}’ 9876.678900
number_ 9876.6789 .2f f’{number_:.2f}’ 9876.68
number_ 9876.6789 09.2f f’{number_:09.2f}’ 009876.68
number_ 9876.6789 09.5f f’{number_:09.5f}’ 9876.67890
number_ 9876.6789 .2f f’{number_:.2f}’ 9876.68
percent 0.98765 % f’{percent:%}’ 98.765000%
percent 0.98765 9.5% f’{percent:9.5%}’ 98.76500%
percent 0.98765 09.4% f’{percent:09.4%}’ 098.7650%
percent 0.98765 09.5% f’{percent:09.5%}’ 98.76500%
number_ 9876.6789 .2e f’{number_:.2e}’ 9.88e+03
number_ 9876.6789 09.2e f’{number_:09.2e}’ 09.88e+03

string = “Python”

var num format f-string output
string Python 20 f’{string:20}’ Python
string Python >20 f’{string:>20}’ Python
string Python <20 f’{string:<20}’ Python
string Python ^20 f’{string:^20}’ Python
string Python >>20 f’{string:>>20}’ >>>>>>>>>>>>>>Python
string Python <<20 f’{string:<<20}’ Python<<<<<<<<<<<<<<
string Python ^^20 f’{string:^^20}’ ^^^^^^^Python^^^^^^^
string Python =^20 f’{string:=^20}’ =======Python=======
阅读全文 »

radioactivedecay 用于放射性核素衰变的简单分析计算的开源包,支持放射性核素、亚稳态和分支衰变的衰变链。

https://github.com/radioactivedecay/radioactivedecay

安装:pip install radioactivedecay

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# %%
# ============ (2) ==================
import radioactivedecay as rd
import matplotlib.pyplot as plt
# 创建一组放射性源项:Inventory
inv = rd.Inventory({'U-235': 1}, 'Ci')

inv_t1 = inv.decay(50, 'd')
print(inv_t1.activities('Bq'))

# 绘图
inv.plot(50, 'd')
inv.plot(50, 'd', order='alphabetical')

# %%
import radioactivedecay as rd
import matplotlib.pyplot as plt

from cycler import cycler

plt.rcParams["font.family"] = "monospace"
cm = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf']
ls = ['-', '--']
mk = ['+', 'x', '*', '^', 's']
me = [31, 71, 91, 113, 161]
cc = (cycler(color=cm) + cycler(linestyle=ls) * (cycler(marker=mk))) + cycler(markevery=me) * 2

DICT = {'U-235': 1e9,
'Rn-222': 1e9}

TIME = iter([10, 1])

for (hesu, huodu) in DICT.items():
t1 = next(TIME)
inv = rd.Inventory({hesu: huodu}, 'Bq')
inv_t1 = inv.decay(t1, 'd')
act_t1 = inv_t1.activities('Bq')

fig_name = f'{hesu} @ {huodu:0.2e} Bq'
fig_note = f'the Activity after {t1} days of Decay:\n'
fig_note += '\n'.join(f'- {k} {v:.2e} Bq' for (k, v) in act_t1.items())
print(fig_name, '\n' ,fig_note)

fig0 = plt.figure(figsize=(9, 9))
plt.gca().set_prop_cycle(cc)

fig, ax = inv.plot(t1, 'd', yscale='log', ymin=1e-8, order='alphabetical', fig=fig0)
plt.title(fig_name)
plt.text(0.3, 0.1, fig_note, transform=ax.transAxes)
plt.grid(True, linestyle=':', color='gray', alpha=0.5)

plt.show()
fig.savefig(f'decay_activity_{hesu}.png', dpi=300)

阅读全文 »

时间字符串格式

ref: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes

Directive Meaning Example
%a Weekday Sun, Mon, …, Sat (en_US)
%A Weekday full name. Sunday, Monday, …, Saturday (en_US)
%w Weekday as a decimal number, where 0 is Sunday . 0, 1, …, 6
%d Day of the month as a zero-padded decimal number. 01, 02, …, 31
%b Month as locale’s abbreviated name. Jan, Feb, …, Dec (en_US);
%B Month as locale’s full name. January, February, …, December (en_US);
%m Month as a zero-padded decimal number. 01, 02, …, 12
%y Year without century as a zero-padded decimal number. 00, 01, …, 99
%Y Year with century as a decimal number. 0001, 0002, …, 2013, 2014, …, 9998, 9999
%H Hour (24-hour clock) as a zero-padded decimal number. 00, 01, …, 23
%I Hour (12-hour clock) as a zero-padded decimal number. 01, 02, …, 12
%p Locale’s equivalent of either AM or PM. AM, PM (en_US);
%M Minute as a zero-padded decimal number. 00, 01, …, 59
%S Second as a zero-padded decimal number. 00, 01, …, 59
%f Microsecond as a decimal number, zero-padded to 6 digits. 000000, 000001, …, 999999
%z UTC offset in the form ±HHMM[SS[.ffffff]] (empty), +0000, -0400, +1030, +063415, -030712.345216
%Z Time zone name (empty string if the object is naive). (empty), UTC, GMT
%j Day of the year as a zero-padded decimal number. 001, 002, …, 366
%U Week number of the year (Sunday as the first day) 00, 01, …, 53
%W Week number of the year (Monday as the first day) 00, 01, …, 53
%c Locale’s appropriate date and time representation. Tue Aug 16 21:30:00 1988 (en_US);
%x Locale’s appropriate date representation. 08/16/88 (None);
%X Locale’s appropriate time representation. 21:30:00 (en_US);
%% A literal ‘%’ character. %
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# === 1. 获取当前时间,返回指定的字符串 ===
import time
now = time.strftime('%Y-%m-%d %H:%M:%S')

print(now)

from datetime import datetime
now = datetime.now().strftime('%Y-%m-%d %a %H:%M:%S')

print(now)


# === 2. 将时间字符串, 转化为时间对象 ===

from datetime import datetime
dt = datetime.strptime('2023-01-01 12:00:00', '%Y-%m-%d %H:%M:%S')

import pandas as pd
pd_dt = pd.to_datetime('2023-01-01 12:00', format='%Y-%m-%d %H:%M')

print(dt)
print(pd_dt)

radioactivedecay 用于放射性核素衰变的简单分析计算的开源包,支持放射性核素、亚稳态和分支衰变的衰变链。

https://github.com/radioactivedecay/radioactivedecay

安装:pip install radioactivedecay

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
32
#%%
import radioactivedecay as rd
import matplotlib.pyplot as plt

# 创建一个放射性核素: Nuclide
ncld = rd.Nuclide('U-235')
half = ncld.half_life('readable') # 半衰期
prog = ncld.progeny() # 衰变产物
frac = ncld.branching_fractions() # 占比
mode = ncld.decay_modes() # 衰变射线类型

print(ncld, mode, prog, frac, half, sep='\n')

# 绘制衰变链
ncld.plot()

#%%
# 列出多个核算衰变类型
NUCs = ['U-235',
'Pu-239']

for name in NUCs:
ncld = rd.Nuclide(name)
half = ncld.half_life('readable')
prog = ncld.progeny()
frac = ncld.branching_fractions()
mode = ncld.decay_modes()
print(ncld, mode, prog, frac, half, sep='\n')

fig, ax = ncld.plot()
fig.savefig(f'decay_chains_{name}.png', dpi=300)

阅读全文 »

pandas 合并数据常用的两个函数:

刚好有一个对比 RNN 和 LSTM 神经网络运行结果的场景分别用到了这两个函数:

  • 采用 concat 合并两个csv表; csv表为两次运行结果的,列名基本一致。
  • 采用 merge 合并模型运行条件类似的表, 用于对比数据
阅读全文 »

一、WSL 安装 Ubuntu22.04

  1. 启用 WSL

  2. 打开 Microsoft Store,安装 Ubuntu22.04

  3. 设置源,更新
    ref: https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

更新:sudo apt update

升级:sudo apt upgrade

  1. 安装 ZSH、oh-my-zsh

参考 zsh & oh-my-zsh 安装配置

二、安装 openmc

ref: https://docs.openmc.org/en/stable/quickinstall.html

  1. 参照 Installing from Source on Ubuntu,安装 openmc。

    安装完成后,运行 openmc 试一下, 提示错误: 找不到材料数据卡 cross_sections.xml

  2. 下载材料数据集

    1
    2
    3
    4
    git clone https://github.com/openmc-dev/data openmc-dev_data

    cd openmc-dev_data
    python3 convert_nndc71.py
    阅读全文 »

ref: https://github.com/ScoopInstaller/Scoop/issues/4390

0. 问题: scoop 本身不支持安装包有解压密码的自动解压。

scoop 本身不支持安装包有解压密码的自动解压。因此在安装 MAS 时会卡在解压处,无法继续安装。

1. 7z 命令手册

7z 命令是支持的: 7z x FILENAME.7z -pPWD -oOUTDIR

2. 查 Scoop 源码的解压函数

找到 Scoop 源码里的 “~\scoop\apps\scoop\current\lib\decompress.ps1” 文件。
文件封装了 Expand-7zipArchive 函数命令, 但参数没有能将密码传入的方法。

3. 试 Scoop 的 pre_install

Scoop Wiki 里提到了 pre_install 等说法。

在 MAS.json 中加入:

1
"pre_install": "7z x $dir\\$fname -p1234 $('-o' + $dir)"

尝试了很多次还是不起作用,Scoop的策略是遇到压缩包先执行解压、再做后续的事情。所以这一句不会被执行,安装程序依旧卡在解压处,无法继续安装。

阅读全文 »

0. 引脚表

ESP8266 裸板是 22 个引脚。

ESP8266 NodeMCU 比较常见的是 ESP-12E, 开发板总共有30个引脚。

  • 开发板的引脚设置了新的丝印编码,与GPIO标号对应需要看图。
  • 在裸板的基础上增加了 3对电源引脚、一对RSV引脚。
  • 增加了一个 MicroUSB口、一个LED灯、两个按键,可以方便调试。

引脚如下图所示:

阅读全文 »

1. 客户端 VSCode 安装 Remote 插件

安装插件, 略

添加远程连接 aaa@192.168.1.xxx, 连接、等待, 输入密码

2. 连接时可能连不上,并出现警告

警告: The remote host may not meet VS Code Server's prerequisitesfor glibc and libstdc++

阅读全文 »

从在线日历获取事件

Outlook 查看日历链接: 设置-日历-共享日历-发布日历,可以看到如下链接:

https://outlook.live.com/owa/calendar/d82e6afe-XXXX-XXXX/cid-YYYY/calendar.ics

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
32
33
34
35
36
37
38
39
from ics import Calendar
import requests

# Parse the URL
url = "https://outlook.live.com/owa/calendar/d82e6afe--XXXX-XXXX/cid-YYYY/calendar.ics"
cal = Calendar(requests.get(url).text)


#%%
# Print all the events
events = sorted(cal.events)
for event in events:
print(event.begin , event.name )

#%%
timeline = cal.timeline
for tl in timeline:
print(tl.begin , tl.name )

# %%
# 获取今天及之后的事件
from ics import Calendar
import requests
import arrow

cal = Calendar(requests.get(url).text)

today = arrow.now()
print(today)
today = arrow.now().replace(hour=0, minute=0, second=0, microsecond=0)
print(today)
today = arrow.now().span('day')[0]
print(today)

evts = cal.timeline.start_after(today)

for evt in evts:
print(evt.begin.strftime("%Y-%m-%d %a %H:%M"), evt.name )

ref: (https://github.com/ScoopInstaller/Scoop/wiki/App-Manifests)

尝试自己制作一个安装配置文件, 软件是 N_m3u8DL-RE

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
{
"version": "v0.2.0-beta",
"description": "Cross-Platform, modern and powerful stream downloader for MPD/M3U8/ISM",
"homepage": "https://github.com/nilaoda/N_m3u8DL-RE",
"license": "MIT",
"suggest": {
"ffmpeg": [
"ffmpeg",
"ffmpeg-nightly"
]
},
"url": "https://github.com/nilaoda/N_m3u8DL-RE/releases/download/v0.2.0-beta/N_m3u8DL-RE_Beta_win-x64_20230628.zip",
"hash": "9e3133f03e112cc57f34bf04234b7857ae7c997c214f0eb510a120739c388652",
"bin": [
"N_m3u8DL-RE_Beta_win-x64/N_m3u8DL-RE.exe",
[
"N_m3u8DL-RE.exe",
"N_m3u8DL_RE"
]
],
"checkver": {
"url": "https://api.github.com/repos/nilaoda/N_m3u8DL-RE/releases",
"regex": "releases/download/(?<tag>[vV]?[\\w-.]+)/N_m3u8DL-RE_Beta_win-x64_(?<date>[\\d.-]+).zip",
"replace": "${tag}"
},
"autoupdate": {
"url": "https://github.com/nilaoda/N_m3u8DL-RE/releases/download/$matchTag/N_m3u8DL-RE_Beta_win-x64_$matchDate.zip"
}
}

阅读全文 »

1 安装 zsh

1
2
3
4
5
sudo apt install zsh

# echo $SHELL # 显示当前 shell 类型
# cat /etc/shells # 显示可使用的 shell
# chsh -s /bin/zsh # 将 zsh 设为默认终端

2 安装 ohmyzsh

ref: https://ohmyz.sh/

  • 用 wget 安装。
    1
    sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

有时候会出现 443 网路错误,可手动下载、安装 install.sh

1
nano zsh-install.sh

打开 https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/install.sh
将安装代码全部复制进去

1
2
sudo chmod +x zsh-install.sh
./zsh-install.sh

3 安装 ohmyzsh (gitee 源)

ref: https://gitee.com/mirrors/oh-my-zsh.git

1
sh -c "$(wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh -O -)"

4 配置 ohmyzsh (gitee 源)

  • 打开配置文件

    1
    nano ~/.zshrc
  • 修改如下:

    1
    2
    3
    4
    5
    # 主题
    ZSH_THEME="ys"

    # 插件
    plugins=(git zsh-autosuggestions zsh-syntax-highlighting )
  • 也可以用命令修改:

    1
    2
    sed -i 's/^ZSH_THEME=.*/ZSH_THEME="ys"/g' .zshrc
    sed -i 's/^plugins=.*/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/g' .zshrc
  • 下载插件

    1
    2
    3
    git clone https://gitee.com/mirrors/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

    git clone https://gitee.com/mirrors/zsh-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

    ref: https://github.com/zsh-users/zsh-autosuggestions

ref: https://github.com/zsh-users/zsh-syntax-highlighting

  • 加载配置文件, 使生效
    1
    source ~/.zshrc

===

1
2
3
4
5
6
7
8
9
10
11
12
sudo apt install zsh -y
sudo apt install git -y

sh -c "$(wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh -O -)"

sed -i 's/^ZSH_THEME=.*/ZSH_THEME="ys"/g' .zshrc
sed -i 's/^plugins=.*/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/g' .zshrc

git clone https://gitee.com/mirrors/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://gitee.com/mirrors/zsh-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

source ~/.zshrc

用 raspberry pico w 和墨水屏做一个 mnist-clock

1. 墨水屏

2. pico w 基本配置

2.1 刷固件

  • https://micropython.org/download/rp2-pico-w/

  • 下载类似rp2-pico-w-20221107-unstable-v1.19.1-616-g5987130af.uf2

  • 首次将 pico w 连接电脑之后,会以U盘形式弹出来,把固件拖进去。

  • 已经刷过固件的,按着板子上的 BOOTTSEL 按钮连接电脑。

重新上电,固件就自动刷好了。

2.2 开发环境 thonny

  • 安装 thonny, scoop install thonny
  • Thonny IED: 打开 ‘运行’ - ‘配置解释器’, 配置一下
  • 运行一下板载的 LED 测试程序:
1
2
3
4
5
6
7
8
9
from machine import Pin 
import time

led = Pin('LED', Pin.OUT)
while(True):
led.on()
time.sleep(1)
led.off()
time.sleep(1)

可以看到板载的 LED 在闪烁。

阅读全文 »