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 cast | |
import logging | |
import json | |
import urllib.request | |
import http.client | |
import urllib.parse | |
logger = logging.getLogger(__name__) | |
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 re | |
PASSWORD_MIN_LENGTH = 8 | |
PASSWORD_MAX_LENGTH = 128 | |
PASSWORD_MIN_UNIQUE_CHARS = 5 | |
PASSWORD_MAX_REPEATED_CHARS = 3 | |
MAX_CONTINUOUS_INCREASING_OR_DECREASING_SEQUENCES = 3 | |
class PasswordValidationError(Exception): |
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
sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list |
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
#!/usr/bin/env bash | |
set -euo pipefail | |
PREFIX=${PREFIX:-~/.local} | |
mkdir -p $PREFIX/bin $PREFIX/lib | |
curl -L https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.36/swagger-codegen-cli-3.0.36.jar \ | |
-o $PREFIX/lib/swagger-codegen-cli.jar | |
echo '#!/usr/bin/env bash' > $PREFIX/bin/swagger-codegen-cli |
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 functools import wraps | |
import asyncio | |
def get_event_loop(): | |
try: | |
return asyncio.get_event_loop() | |
except RuntimeError as e: | |
if "There is no current event loop in thread" in str(e): | |
loop = asyncio.new_event_loop() |
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 camel_case_to_snake_case(s: str, use_fat: bool = False) -> str: | |
""" | |
>>> camel_case_to_snake_case("ProcedureContextStatus") | |
"procedure_context_status" | |
>>> camel_case_to_snake_case("ProcedureContextStatus", use_fat=True) | |
"PROCEDURE_CONTEXT_STATUS" | |
""" | |
chars = [s[0].upper() if use_fat else s[0].lower()] | |
for c in s[1:]: | |
if c in ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'): |
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 functools import wraps | |
import asyncio | |
def get_event_loop(): | |
try: | |
return asyncio.get_event_loop() | |
except RuntimeError as e: | |
if "There is no current event loop in thread" in str(e): | |
loop = asyncio.new_event_loop() |
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
#!/usr/bin/env bash | |
# Mainly used with GitLab CI/CD | |
# Original source link of this file: | |
# https://gist.github.com/wonderbeyond/434d3622c2db3d5ff00b4ba4a2a667bc | |
set -euo pipefail | |
export POETRY_HOME=~/poetry | |
command -v curl > /dev/null || apt-get install -y curl |
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
"""Thanks to https://gist.github.com/butla/2d9a4c0f35ea47b7452156c96a4e7b12""" | |
import socket | |
import time | |
def wait_port_ready(port: int, host: str = 'localhost', timeout: float = 5.0): | |
""" | |
Wait until a port starts accepting TCP connections. |
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 Union, Any, List, Dict, Iterable | |
import functools | |
def _get(data, key: Union[str, int], default=None) -> Any: | |
""" | |
Get value from dict or list by key (integer or string). | |
""" | |
if isinstance(data, dict): | |
return data.get(key, default) |