This file contains 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
""" | |
pip install fastapi uvicorn starlette watchdog | |
uvicorn detect_file_updates:app --reload | |
""" | |
import asyncio | |
import os | |
from fastapi import FastAPI, WebSocket, WebSocketDisconnect | |
from fastapi.responses import HTMLResponse |
This file contains 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
<!-- | |
## usage | |
### (1) | |
Specify a relative path. | |
The Single File Component does not resolve the relative path to the figure, so the img tag is required. | |
```markdown | |
<vuepress-card href="../relative/path/to/directory/"> | |
<img src="../relative/path/to/directory/img.jpg"> | |
</vuepress-card> |
This file contains 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
// original | |
// https://github.com/vuejs/vuepress/blob/ba7f586e2e8173e5e30c345ea6a92ff213925a2e/packages/%40vuepress/theme-default/util/index.js#L188-L215 | |
/** | |
* @param { Route } route | |
* @param { Array<string|string[]> | Array<SidebarGroup> | [link: string]: SidebarConfig } config | |
* @returns { base: string, config: SidebarConfig } | |
*/ | |
export function resolveMatchingConfig (regularPath, config) { | |
if (Array.isArray(config)) { |
This file contains 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
def snake_to_kebab(identifier): | |
if isinstance(identifier, list): | |
container = range(len(identifier)) | |
for element in container: | |
snake_to_kebab(identifier[element]) | |
elif isinstance(identifier, dict): | |
container = [key for key in dict.keys()] | |
for element in container: | |
snake_to_kebab(getattr(identifier, element)) |
This file contains 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
"""script for scraping images. | |
1) overview | |
input: site URL | |
output: image files | |
2) usage | |
$ python scrape_image.py https://pt.wikipedia.org/wiki/Veneza | |
3) prerequisite | |
$ pip3 install requests, bs4 | |
4) concept | |
1) Get thumnail URL. |
This file contains 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
"""Check the obj is immutable or not by adding new attribute or sequence. | |
USAGE: | |
isimmutable(var) | |
WARNING: | |
This code cannot precisely check immutability, | |
because Python has the mechanisms to cutomize attribute access, | |
such as property and descriptor. |
This file contains 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 random | |
import time | |
N = 100000 | |
lst1 = [random.randint(0, 9) for _ in range(N)] | |
lst2 = lst1.copy() | |
# insert | |
start1 = time.time() |
This file contains 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
"""Compare two list.""" | |
def equal_list(lst1, lst2): | |
lst1 = lst1.copy() | |
for element in lst2: | |
try: | |
lst1.remove(element) | |
except ValueError: | |
return False |
This file contains 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 collections | |
def sample(): | |
# point 1. 属性はデコレータに文字列で与える。 | |
@immutable( | |
'x1', 'y1', 'x2', 'y2', | |
'is_rectangle', 'is_line', 'is_dot') | |
class Region(object): | |
# point 2. __init__ ではなく、__new__ を使う。 |
This file contains 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
""" | |
# 概要 | |
immutable なオブジェクトを生成するメタクラス Immutable | |
属性参照は速いけど | |
namedtuple: 0.07781907100070384 | |
自作したクラス: 0.04243788100029633 | |
インスタンス化は遅い |
NewerOlder