Skip to content

Instantly share code, notes, and snippets.

View myuanz's full-sized avatar

provefar myuanz

View GitHub Profile
@myuanz
myuanz / dict_project.py
Last active June 1, 2020 15:10
Python dict project / Python字典投影
from typing import Union, Dict, Any, Callable
from inspect import isfunction, isclass
class ChangeName:
name = ""
def __init__(self, name):
self.name = name
@myuanz
myuanz / .sh
Created January 2, 2020 02:51
View git add and delete lines / 查看 git 增删行数
git log --author="myuanz" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s|%.2f%%, removed lines: %s|%.2f%%, total lines: %s\n", add, add/(add + subs)*100, subs, subs/(add + subs)*100, loc }' -
@myuanz
myuanz / .sh
Created January 2, 2020 02:53
Linux 解压
tar –xvf file.tar //解压 tar包
tar -xzvf file.tar.gz //解压tar.gz
tar -xjvf file.tar.bz2 //解压 tar.bz2
tar –xZvf file.tar.Z //解压tar.Z
@myuanz
myuanz / .sh
Last active May 20, 2020 09:22
新Ubuntu配置镜像和公钥
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
" > /etc/apt/sources.list
@myuanz
myuanz / dataclasses.py
Created April 21, 2020 04:19
Dataclasses 的一个轮子 / Homemade Dataclasses
class DataclassesBase:
def __init__(self, **data):
self._annotations = self.__annotations__ if hasattr(self, "__annotations__") else {}
annotations = self._annotations.copy()
for key, value in data.items():
if key in annotations:
if isinstance(value, annotations[key]):
self.__dict__[key] = value
annotations.pop(key)
@myuanz
myuanz / compressed_image.py
Last active May 25, 2020 09:04
Image to ndarray; Image to bytes buffer; Image to buffer pickle; Pickle to Image. Pickle to ndarray
from __future__ import annotations
import io
from functools import lru_cache
from PIL import Image
import numpy as np
import pickle
import os
@myuanz
myuanz / calculator.py
Created November 15, 2020 10:49
简单的 Python 带括号四则运算计算器 / Simple Python elementary arithmetic calculator
def merge(ops: list[str], values: list[int], final_merger=False):
priority = {'*': 1, '/': 1, '+': 2, '-': 2, '$': 9999}
while True:
if len(ops) >= 2:
last, last_last = [ops.pop() for _ in range(2)]
if final_merger:
last_last, last = last, last_last
elif len(ops) >= 1 and len(values) >= 2:
last_last, last = ops.pop(), '$'
else:
@myuanz
myuanz / dynamic-enum.py
Last active July 23, 2022 04:23
Dynamic enum with FastApi
from random import randint
from fastapi import FastAPI
from enum import Enum
app = FastAPI()
class DynamicEnum(Enum):
pass
from pathlib import Path
import re
import html
posts = list(Path('_posts').glob('*.md'))
for post_p in posts:
content = post_p.read_text(encoding='utf-8')
content = content.replace('<pre><code>', '<pre><code class="language-text">')
content = content.replace('&quot;', '"')