"Programs must be written for people to read, and only incidentally for machines to execute." — Harold Abelson
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import UserDict | |
class RememberMissingKeysDict(UserDict): | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
self.missing_keys = set() | |
def get(self, k, default_v=None): | |
if super().get(k) is None: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Test if site allow to be crawled with respect to `robots.txt` | |
ref: https://stackoverflow.com/a/64495913/11487798 | |
""" | |
import requests | |
from protego import Protego | |
from urllib.parse import urlparse | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
change `$` delimiter to `\(` and `\)` pair, at mathjax | |
""" | |
import itertools | |
delimiters = iter(itertools.cycle(["\(", "\)"])) | |
# from https://math.stackexchange.com/questions/3307627 | |
original = r"""The point is that all rational numbers can be expressed in lowest terms. They don't have to be. Yes, $\frac 24$ is a perfectly good rational number, but the same number can be expressed as $\frac 12$. When we prove $\sqrt 2$ is irrational, we assume it is rational, then say to express that rational in lowest terms as $\frac ab$. The reason to do that is that we then show both $a$ and $b$ are even, so $\frac ab$ is not in lowest terms. If we had not assumed it was in lowest terms we would not have the contradiction we are seeking.""" | |
new = "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
; 来源:http://www.yinwang.org/blog-cn/2012/08/01/interpreter | |
;;; 以下三个定义 global-env, ext-env, lookup 是对环境(environment)的基本操作: | |
;; 空环境 | |
(define global-env '()) | |
;; 扩展:对环境 env 进行扩展,把 x 映射到 v,得到一个新的环境 |
OlderNewer