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 | |
def get_tokens_with_entities(raw_text: str): | |
raw_tokens = re.split(r"\s(?![^\[]*\])", raw_text) | |
entity_value_pattern = r"\[(?P<value>.+?)\]\((?P<entity>.+?)\)" | |
entity_value_pattern_compiled = re.compile(entity_value_pattern, flags=re.I|re.M) | |
tokens_with_entities = [] | |
for raw_token in raw_tokens: | |
match = entity_value_pattern_compiled.match(raw_token) |
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 Generic, TypeVar | |
import numpy as np | |
from pydantic.fields import ModelField | |
JSON_ENCODERS = { | |
np.ndarray: lambda arr: arr.tolist() | |
} | |
DType = TypeVar('DType') |
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 inspect | |
from typing import Any, Callable, List, Type, TypeVar, Union, get_type_hints | |
from fastapi import APIRouter, Depends | |
from pydantic.typing import is_classvar | |
from starlette.routing import Route, WebSocketRoute | |
T = TypeVar("T") | |
CBV_CLASS_KEY = "__cbv_class__" |
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
// This configuration is not mine but found on a german forum, and modified for my needs. I'm sharing because all info are in german | |
// Comment about a more secure VPN cfg are welcome, this is mere cut and past because testing is slow | |
// | |
// On the OPNSense side, configure the IPSEC tunnel in this way | |
// Tunnel Setting: | |
// | |
// - Connection method: I've put "Respond only" because the OPNSense is installed on stable server | |
// - Key Exchange version: V1 | |
// - Internet Protocol: IPv4 | |
// - Interface: WAN |
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 load_kv(): | |
'''This magical function lookup module name, and load the kv file | |
with the same name (in the same directory) | |
''' | |
filename = inspect.currentframe().f_back.f_code.co_filename | |
f = extsep.join((splitext(filename)[0], 'kv')) | |
if exists(f) and f not in Builder.files: | |
Builder.load_file(f) | |