Markdown
2018-07-21
vscode 或者 Typora 或这其他的一些编辑器都支持在 Markdown 中使用数学公式,直接预览就行了。
但是如果是自己做 Markdown 转换,生成 HTML 页面,就必须做点额外的工作。
我发现 Mathjax 挺好用的,只需加入三行:
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script
src="https://cdn.jsdelivr.net/npm/mathjax@3.0.1/es5/tex-mml-chtml.js"
async
></script>
<script>
MathJax = {
tex: {
inlineMath: [
["$", "$"],
["\\(", "\\)"],
],
},
};
</script>
Katex 据说不错,以后如果发现 Mathjax 有不足之处再试试。
Update @ 2022-05-27: 根据 May 19, 2022 的博客 Render mathematical expressions in Markdown, GitHub 开始采用 Mathjax 渲染数学公式。
关于数学公式
数学公式的语法都是参考 LaTeX(2019/07/21, LaTeX)。
Linux Shell
2018-07-17
CURRENT_PATH=$(dirname $(readlink -f "$0"))
开发工具 编辑器
2018-07-13
Pico (Pine composer) is a text editor for Unix and Unix-like computer systems. It is integrated with the Pine and Alpine email clients, which were initially designed by the Office of Computing and Communications at the University of Washington.
A clone of Pico called nano, which is part of the GNU Project, was developed because Pico's earlier license had unclear redistribution terms. Newer versions of Pico as part of Alpine are released under the Apache License version 2.0.
Nano 是由于 Pico 编辑器早期授权条款不够 free 而开发,是 GNU 计划的一部分。
使用
Nano 是一个超级轻量级的文本编辑器,是每个 Linux 发行版的标配。
- 语法高亮(比如:
/usr/share/nano/json.nanorc)
两个命令:nano,rnano(受限模式,参考 man 文档)
配置
- 系统配置
/etc/nanorc,/usr/share/nano/
- 用户配置
~/.nanorc,~/.nano/
参考资料与拓展阅读
DNS
2018-07-10
DNS
2018-07-07
Linux
2018-07-03
date
2018年 07月 03日 星期二 14:09:28 CST
# locale 格式
date +"%c"
2018年07月03日 星期二 14时09分22秒
# RFC3339 格式
date --rfc-3339=s
2018-07-03 14:09:48+08:00
# UTC 时间,ISO 8601 格式
date -u +"%Y-%m-%dT%H:%M:%SZ"
# yyyy-mm-dd hh:mm:ss,mm
date +'%Y-%m-%d %H:%M:%S,%3N'
2018-07-03 14:09:20,902
# 获取时间戳
date +%s
# 时间字符串转时间戳
date -d "2018-07-03 14:09:00" +%s
1530598140
date -d "2018-07-03 14:09:00" +%s --utc
1530626940
# 时间戳转时间字符串
date -d @1530598140
2018年 07月 03日 星期二 14:09:00 CST
date +'%Y-%m-%d %H:%M:%S' -d @1530598140
2018-07-03 14:09:00
# 获取一分钟前的时间
date --rfc-3339=s -d '1 min ago'
date --rfc-3339=s -d '1 minute ago'
date --rfc-3339=s -d '1 minutes ago'
# 获取一个小时前的时间
date --rfc-3339=s -d '1 hour ago'
开发者
2018-06-26
我本来就想记录一下请求搜集服务的,结果扩大化,发现完全兜不住,好吧,就这样吧!
Linux
2018-06-12
total 内存总数
used 使用内存
free 未使用内存
shared Memory used (mostly) by tmpfs (Shmem in /proc/meminfo)
buffers Memory used by kernel buffers (Buffers in /proc/meminfo)
cached Memory used by the page cache and slabs (Cached and SReclaimable in /proc/meminfo)
available 可用内存
SMS
2018-06-08
短信的通信协议从 2G 时代一直到现在基本没有什么变化。
- 支持 140 个字节(140 Byte = 140 * 8 bit = 1120 bit)
- 支持 GSM-7 编码,8bit 编码,UCS-2 编码
- GSM-7 每个字符 7 bit,支持英语和西欧语言,配合 National Language Shift Table 功能,能够支持一些其他字母文字的语言。
- UCS-2 每个字符 2 Byte(16 bit),传递一些 GSM-7 框架不支持的语言,比如中文(字符太多,7bit 方案反倒不合适)。
- 8bit 用来传递图片等二进制数据。
- 根据短信协议,如果长度超出范围,需要在短信前面加上一个二进制头部,叫做 UDH(User Data Header)。
- UDH 一共 6 个字节
- 包含一些 SMS 拓展字段
- 对于短信拆分来讲,里面有这一批短信的总条数,和当前这条短信的序号
所以,
- 如果是中文短信,用 UCS-2 编码,每个字符 2 Byte,一条短信最长支持 70 个中文字符(140 Byte / 2)。
- 注意:所有字符,包括 ASCII 中的英文、数字、半角的标点,全部需要转换成 UCS-2 的 2 Byte 编码。
- 如果长于 70 个字符,就需要切割成多条,UDH 头部需要 6 Byte,每条短信还剩 134 Byte,除以二,还能装 67 个字符。
- 例如:140 个中文字符的短信,需要切割成 67 + 67 + 6 三条短信。
- 如果是英文短信,或者部分西欧语言,可以使用 GSM-7 编码,每个字符 7 bit,一条短信最长支持 160 个字符(1120 bit / 7)。
- 如果长于 160 个字符,也是需要切割,除去 UDH 的 6 Byte = 6 _ 8 bit = 48 bit,还剩 1120 bit - 48 bit = 1072 bit,
1072 bit = 7 bit _ 153 + 1 bit,也就是说最多发送 153 个字符(多的那 1 bit 置 0,不参与计费)。
- 例如,320 个英文字符,需要切割成 153 + 153 + 14 三条短信。
- 注意:GSM-7 编码中,9 个拓展字符
^ ~ \ | { } [ ] € 需要算两个字符。非常重要
- 数据通信中都是使用 Byte 为单位,用 GSM-7 编码可能会除不尽,也就是说剩余 1 ~ 7 bit。比如:
- 发送 33 个字,33 * 7 bit = 231 bit,需要 29 Byte (232 bit) 来装,就多了 1 bit
- 同样的方法计算,发送 34 个字多了 2 bit,... 发送 39 个字剩余 7 bit,发送 40 个字正好 35 Byte,没有多余的 bit...
- 根据协议,多余的 bit 需要置零,除非是多出来 7 bit,7 个 0 会和 GSM-7 的
@ 字符冲突,这时候应该置为 0001101,也就是 GSM-7 中的 \r 回车字符。
最后:
- 关于 GSM-7 的详细信息,可以参考:2022/01/05,GSM-7 编码。
- 关于 UDH 的详细信息,可以参考:2022/05/13,CMPP: UDHI 头。
- https://en.wikipedia.org/wiki/Concatenated_SMS
补充:
- 部分通道采用 7 Byte 的 UDH (短信批次标识由 1 Byte 改成 2 Byte),所以短信切割长度是 152 个字符((140 - 7) * 8 / 7)。
- 如果短信采用 GSM-7 编码,UDH 需要按 7 bit 对齐,也就是说如果是 6B 的 UDH,最后需要占用 49 bit,UDH 后面的 1 bit 填 0。
Python
2018-05-26
首先你得有 PyPI 的账号,没有注册的话,不用搞了。
然后你肯定要先准备 setup.py 了,如果这个都没弄就不用搞了。
算了,先贴一个简单的样板吧。
setup.py
# -*- coding: utf-8 -*-
from setuptools import setup
setup(
name='PageageName',
version='0.0.1',
author='YourName',
author_email='YourEmail',
url='PackageSite (e.g. GitHub)',
description='....',
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
packages=['PackageDir'],
install_requires=[
'requests>=2.18.4',
'balabala',
],
extras_require={ # 可选
'dev': [
'balabala...',
],
'test': [
'balabala...',
],
},
classifiers=[
'Development Status :: 3 - Alpha',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'License :: OSI Approved :: MIT License',
],
)
流程
python3 -m pip install twine
rm -rf dist
python3 setup.py sdist bdist_wheel
python2 setup.py sdist bdist_wheel
twine upload dist/*
twine 会询问账号密码,如果不想每次这么麻烦,可以创建 ~/.pypirc 文件。
.pypirc 文件
[distutils]
index-servers =
pypi
[pypi]
repository = https://upload.pypi.org/legacy/
username = your_username
password = your_password
参考资料