"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
#lang racket | |
; 来源:http://www.yinwang.org/blog-cn/2012/08/01/interpreter | |
;;; 以下三个定义 global-env, ext-env, lookup 是对环境(environment)的基本操作: | |
;; 空环境 | |
(define global-env '()) | |
;; 扩展:对环境 env 进行扩展,把 x 映射到 v,得到一个新的环境 |
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
""" | |
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
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
const MiddlewarePipeline = () => { | |
const _middlewares = [] | |
return { | |
apply: middleware => _middlewares.push(middleware), | |
run: function run (middlewares) { | |
if (!middlewares) { | |
// set for first time call `run` | |
middlewares = _middlewares |
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
import datetime as dt | |
from collections import namedtuple | |
SUNDAY = "Sunday" | |
yearweek = namedtuple("yearweek", ["year", "week"]) | |
def get_weekday(date: dt.date) -> str: | |
""" |
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
# docker run -d -p 4444:4444 -p 7900:7900 --shm-size="2g" selenium/standalone-chrome:4.1.0-20211209 | |
from selenium import webdriver | |
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities | |
driver = webdriver.Remote("http://127.0.0.1:4444/wd/hub", DesiredCapabilities.CHROME) | |
driver.get("http://www.google.com") | |
driver.save_screenshot("test.png") | |
driver.quit() |
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
#!/usr/bin/python | |
import os | |
def save_path(): | |
import datetime as dt | |
from pathlib import Path | |
# file-naming | |
# https://softwareengineering.stackexchange.com/questions/61683/standard-format-for-using-a-timestamp-as-part-of-a-filename |
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
import pyperclip | |
import json | |
def object2json_and_copy_it_to_clipboard(obj): | |
""" | |
convert any object jsonable(if need), and dumps it | |
copy to clipboard | |
""" | |
if hasattr(obj, "__dict__"): |
NewerOlder