#350 读史书:兔死狗烹

2019-11-26

范蠡遂去,自齐遗大夫种书曰:“蜚鸟尽,良弓藏;狡兔死,走狗烹。越王为人长颈鸟喙,可与共患难,不可与共乐。子何不去?” 种见书,称病不朝。人或谗种且作乱,越王乃赐种剑曰:“子教寡人伐吴七术,寡人用其三而败吴,其四在子,子为我从先王试之。” 种遂自杀。
《史记 越王勾践世家》

上令武士缚信,载后车。信曰:“果若人言,‘狡兔死,良狗亨;高鸟尽,良弓藏;敌国破,谋臣亡。’天下已定,我固当亨!” 上曰:“人告公反。” 遂械系信。至雒阳,赦信罪,以为淮阴侯。
《史记 淮阴侯列传》

中国哲学书电子化计划

#347 容错、高可用、灾备

2019-11-19

阮一峰的博文(容错,高可用和灾备)中说:

  • 容错:发生故障时,如何让系统继续运行。
    飞机的四个引擎坏了一个还能继续飞行,汽车的四个轮子坏了一个也能将就驾驶。
  • 高可用:系统中断时,如何尽快恢复。
    汽车的备胎,用于快速恢复正常驾驶(允许短暂的业务中断)。
  • 灾备:系统毁灭时,如何抢救数据。
    飞机的弹射装置,保证最核心的“资产” —— 驾驶员能够存活。

#346 开发者 Cheatsheets

2019-11-18

Linux

  • https://linuxopsys.com/topics/linux-commands-cheat-sheet
  • grep
  • awk

Bash & ShellScripting

  • https://oit.ua.edu/wp-content/uploads/2020/12/Linux_bash_cheat_sheet-1.pdf
  • http://www.cheat-sheets.org/saved-copy/shellscripcheatsheet.pdf

Linux Network

  • https://opensource.com/downloads/cheat-sheet-networking
    • https://opensource.com/sites/default/files/gated-content/osdc_cheatsheet-networking-2021.4.8.pdf
  • Hacking Tools Cheat Sheet

Windows

cmd

  • http://www1.cs.columbia.edu/~sedwards/classes/2017/1102-spring/Command%20Prompt%20Cheatsheet.pdf
  • https://phoenixnap.com/kb/wp-content/uploads/2023/01/windows-cmd-commands-cheat-sheet-pdf.pdf

PowerShell

  • http://ramblingcookiemonster.github.io/images/Cheat-Sheets/powershell-basic-cheat-sheet2.pdf

Vim

  • https://phoenixnap.com/kb/vim-commands-cheat-sheet
  • https://www.cs.cmu.edu/~15131/f17/topics/vim/vim-cheatsheet.pdf
  • https://github.com/dennyzhang/cheatsheet-vim-A4
    • https://github.com/dennyzhang/cheatsheet-vim-A4/blob/master/cheatsheet-vim-A4.pdf
  • https://gitee.com/chloneda/vim-cheatsheet

Python

  • https://hackr.io/blog/python-cheat-sheet
  • https://www.pythoncheatsheet.org/
  • https://static.realpython.com/python-cheat-sheet.pdf
  • https://static.realpython.com/python_cheat_sheet_v1.pdf
  • https://courses.cs.washington.edu/courses/cse163/22wi/resources/python-cheat-sheet.pdf

Django

  • http://cheat-sheets.org/saved-copy/django_reference_sheet.pdf
  • https://cheatography.com/ogr/cheat-sheets/django/
  • https://edu.anarcho-copy.org/Programming%20Languages/Python/Python%20CheatSheet/beginners_python_cheat_sheet_pcc_django.pdf
  • https://www.riptutorial.com/Download/django-rest-framework.pdf
  • https://books.agiliq.com/_/downloads/django-api-polls-tutorial/en/latest/pdf/

NumPy

  • http://www.cheat-sheets.org/saved-copy/numpy-cheat-sheet.20210604.pdf

Golang

  • http://www.cheat-sheets.org/saved-copy/go-lang-cheat-sheet-master.20181212/golang_refcard.pdf
  • https://golang.sk/images/blog/cheatsheets/go-cheat-sheet.pdf
  • https://github.com/fedir/go-tooling-cheat-sheet
    • https://raw.githubusercontent.com/fedir/go-tooling-cheat-sheet/master/go-tooling-cheat-sheet.pdf

C/C++

  • http://dcjtech.info/wp-content/uploads/2017/09/C-Programming.pdf
  • https://cheatography.com/ashlyn-black/cheat-sheets/c-reference/
  • https://opensource.com/sites/default/files/gated-content/cheat_sheet_c.pdf
  • https://courses.cs.washington.edu/courses/cse351/14sp/sections/1/Cheatsheet-c.pdf
  • https://web.pa.msu.edu/people/duxbury/courses/phy480/Cpp_refcard.pdf
  • https://cheatography.com/technecure/cheat-sheets/c-cheatsheet/
  • https://cppcheatsheet.readthedocs.io/_/downloads/en/latest/pdf/
  • https://cheatography.com/benjy/cheat-sheets/c/

Java

  • https://computinglearner.com/wp-content/uploads/2021/09/Java-Cheat-Sheet.pdf

PHP

  • https://websitesetup.org/wp-content/uploads/2020/09/PHP-Cheat-Sheet.pdf

Web

HTML

  • https://html.com/wp-content/uploads/html-cheat-sheet.pdf

CSS

  • https://websitesetup.org/wp-content/uploads/2019/11/wsu-css-cheat-sheet-gdocs.pdf

JavaScript

  • https://websitesetup.org/wp-content/uploads/2020/09/Javascript-Cheat-Sheet.pdf

jQuery

  • https://websitesetup.org/wp-content/uploads/2017/01/wsu-jquery-cheat-sheet.pdf
  • https://cheat-sheets.org/saved-copy/wsu-jquery-cheat-sheet.pdf

Vue

  • https://learnvue.co/LearnVue-Vue-3-Cheatsheet.pdf
  • https://vuejs-tips.github.io/cheatsheet/vuejs-cheatsheet.pdf

Redis

  • http://stephendavies.org/cpsc350/redisCheatSheet.pdf

MySQL

  • https://phoenixnap.com/kb/wp-content/uploads/2021/04/MySQL-Commands-Cheat-Sheet-by-PhoenixNAP.pdf

MongoDB

  • https://cheatography.com/isaeus/cheat-sheets/mongodb/
  • http://stephendavies.org/cpsc350/mongoCheatSheet.pdf
  • https://www.goalkicker.com/MongoDBBook/MongoDBNotesForProfessionals.pdf

RabbitMQ

  • https://pika.readthedocs.io/_/downloads/en/stable/pdf/

工具

Git

  • https://education.github.com/git-cheat-sheet-education.pdf

Excel

  • https://download.microsoft.com/download/5/4/c/54cd97c1-0213-46a7-b659-95f1c9145f42/Excel_shortcuts_cheat_sheet.pdf

PyTorch

  • https://www.mad.tf.fau.de/files/2019/07/pytorch-cheatsheet-en.pdf

#345 Python sys.audit

2019-11-06

在学习 subprocess 模块的时候看到代码中有一行:

sys.audit("subprocess.Popen", executable, args, cwd, env)

才了解到 Python 3.8 中新加了这样一个审计功能。

作用

提供一种机制,对 Python 程序执行过程中的部分关键操作进行干预,比如记录事件、引发异常、中止操作或完全终止进程。

部分关键操作发生的时候,Python 会调用我们定义的钩子方法。

注意:官方提示,恶意代码可以轻易绕过这些钩子,不要指望审计钩子能用来创建一个安全的 sandbox。
注意:sys.addaudithook 方法的调用会触发一个同名的事件。如果现有的钩子方法抛出 Runtime 异常,则不会添加这个钩子。

支持的审计事件

CPython 定义了一些事件:Audit events table,比如:

  • import
  • exec
  • compile
  • os.exec
  • os.listdir
  • os.rmdir
  • os.spawn
  • os.walk
  • os.system
  • subprocess.Popen

使用

sys.audit 方法是官方定义和执行的,Python 运行时负责抛出审计事件,我们程序只管使用系统方法 sys.addaudithook(hook) 来添加审计钩子处理这些事件。

import sys

def hook(event, args):
    print('%s: %r' % (event, args))

sys.addaudithook(hook)

import math
num = math.ceil(100 / 3)
print(num)

#344 电磁波与可见光

2019-11-03

光、电、磁三者好像完全没有关系。但是近代的一些科学研究表明它们其实是一种东西 —— 电磁波。

1873 年,42 岁的麦克斯韦出版了《论电和磁》,预言了电磁波的存在,同时认为光是电磁波的一种。
PS: 1879 年,48 岁的麦克斯韦因病去世,同年,爱因斯坦诞生。

1905 年,奇迹之年,最著名的“民科” —— 26 岁的专利局职员爱因斯坦发表了一篇论文《On the Electrodynamics of Moving Bodies》,中文翻译为“论动体的电动力学”。论文中指出,电和磁是在不同参考系中观察到的同一种现象。

最后,科学家发现 光、电、磁 的本质,和微观粒子,和量子力学有很大的关系。

我敢说,对于 光、电、磁 三者本质的认知,目前,最顶尖的科学家也不敢打包票。

什么是光?

我们所说的光,又称之为可见光,与紫外线、红外线、X 光等区分开。
实质上来讲,可见光只是电磁波谱上一小段频谱,我们的肉眼对这一段比较敏感而已。
PS: 不同动物对不同频段的电磁波敏感度不同,所以其他动物(比如昆虫)看到的世界和我们很大有很大差异。

img

高中物理就告诉我们:

  1. 光是一种电磁波,波长在 500nm 左右。
  2. 光是由光子组成的粒子流。
  3. 光同时具有波的特性、粒子的特性,这叫做波粒二象性。

电和磁

我们初中就开始学习电,老师教我们,电是由于电子运动产生的物理现象。通过施加电压,电子就会沿着电场运动。

磁则来自磁铁,或者电流。

电磁波

电磁波是指同相振荡且互相垂直的电场与磁场,在空间中以波的形式传递能量和动量,其传播方向垂直于电场与磁场的振荡方向。

  1. 电场和磁场相互垂直,同生同灭。
  2. 电场和磁场同相振荡。
  3. 电磁波可以传输能量和动量。

左手定律,右手定律,相信很多朋友记忆深刻。

电磁波的频率

img

频率由低到高(波长由长到短):

  • 无线电波: 300GHz 1mm ~ 3KHz 100km
  • 微波: 300MHz ~ 300GHz 1m
  • 我们的微波炉 2.45GHz。
  • 红外线 760nm ~ 1000nm (1mm)
  • 可见光 380nm ~ 780nm
  • 紫外线 10nm ~ 400nm
  • X 射线 0.01nm ~ 10nm
  • 伽马射线(γ射线): 小于 0.01nm
  • 用于医疗:放射治疗(放疗)、伽马刀
  • 超新星爆发

为什么光能透过空气、水、玻璃,不能透过墙壁?

参考资料与拓展阅读

#343 尝试 K8S(Kubernetes)

2019-10-15

安装

安装 minikube

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && sudo install minikube-linux-amd64 /usr/local/bin/minikube
$ minikube version
minikube version: v1.0.0

安装 kubectl

https://packages.cloud.google.com/apt/doc/apt-key.gpg
https://apt.kubernetes.io/

sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubectl kubelet kubeadm

Docker 的配置文件:~/.docker/config.json。至少,docker login 之后会生成一个。

~/.minikube/

apt-get update && apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl

参考资料与拓展阅读