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
class DynamicAccessDict(dict): | |
""" | |
A dict-like class that allows accessing LineCol object with multi-level keys in a list | |
Example: | |
config == { | |
'a': { | |
'b': 0, # int value | |
'c': [{'d': 3}] # list value | |
} | |
} |
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
git log --pretty=format:'%h%x00%an%x00%ad%x00%s%x00' --since="2023-07-12" --until="2023-07-13" --date=format:'%Y-%m-%d' | \ | |
jq -R -s '[split("\n")[:-1] | map(split("\u0000")) | .[] | { | |
"commit": .[0], | |
"author": .[1], | |
"date": .[2], | |
"summary": .[3] | |
}]' | \ | |
jq -r '"||Commit||Author||Date||Summary||", | |
( .[] | "|\(.commit)|\(.author)|\(.date)|\(.summary)|" )' | |
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
alias ga='git add' | |
alias gaa='git add .' | |
alias gb='git branch' | |
alias gc='git checkout' | |
alias gcb='git checkout -b' | |
alias gdc='git diff main...' | |
alias gps='git push' | |
alias gpc='git push origin $(git rev-parse --abbrev-ref HEAD)' | |
alias gpl='git pull' | |
alias gd='git diff' |
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 os | |
def scantree(path): | |
"""Recursively yield DirEntry objects for given directory.""" | |
for entry in os.scandir(path): | |
if entry.is_dir(follow_symlinks=True): | |
yield from scantree(entry.path) | |
else: | |
yield entry |
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
{ | |
"$schema": "http://json-schema.org/draft-07/schema#", | |
"title": "Meta-schema of a jsonschema to disallow Python dictionary method names to be used as property names", | |
"description": "Checks forbidden properties in json objects recursively. Jsonschema keywords need to be conditionally excluded.", | |
"type": "object", | |
"allOf": [ | |
{ | |
"$ref": "#/definitions/forbidden-properties" | |
} | |
], |
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
! Video | |
||*.video.qq.com^ | |
||wx.qlogo.cn^ | |
||cwx.qlogo.cn^ | |
||sgshort.wechat.com^ | |
||sgminorshort.wechat.com^ | |
||sglong.wechat.com^ | |
||mmhead.c2c.wechat.com^ | |
||snsvideo.c2c.wechat.com^ | |
||www.qq.com^ |
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
class DictObjMap(dict): | |
""" | |
Converts dict to object attributes for easier value fetching | |
It supports fetching nested dict and list value like `obj.array[0].item` | |
Invalid list index and non-existing key will throw out IndexError and KeyError like native list and dict | |
Can be migrated to dataclasses once Python is upgraded to >=3.7 | |
Side effect: | |
Namespace of builtin dict method attributes is overridden with config keys, only other than get(). | |
Use dict() when calling dict methods, like `dict(obj.array[0].item).items()` |
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
// ==UserScript== | |
// @name Weee Better Style | |
// @namespace https://gist.github.com/gyli/2a49803463d72e7b34cfbecad936c0f1 | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author Guangyang Li | |
// @match https://www.sayweee.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=sayweee.com | |
// @grant GM_addStyle | |
// @run-at document-start |
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
// ==UserScript== | |
// @name Youtube Restyle | |
// @namespace https://gist.github.com/gyli/5ab596a955b8d31883f02fbefde1cfef | |
// @version 0.1 | |
// @description Update Youtube player position to avoid unexpected scrolling | |
// @author Guangyang Li | |
// @match https://www.youtube.com/* | |
// @grant GM_addStyle | |
// @run-at document-start | |
// ==/UserScript== |
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
from typing import Decimal, Tuple | |
def calculate_decimal_range(precision: int, scale: int) -> Tuple[Decimal, Decimal]: | |
""" | |
This method calculates the range of Decimal with given precision and scale. | |
:return: (min_value, max_value) | |
""" | |
precision, scale = Decimal(precision), Decimal(scale) | |
max_value = 10**(precision-scale) - 10**-scale | |
return -max_value, max_value |
NewerOlder