Skip to content

Instantly share code, notes, and snippets.

View tafaust's full-sized avatar
💻
Coding

Thomas Faust tafaust

💻
Coding
View GitHub Profile
@jangedoo
jangedoo / ner_data_maker.py
Created April 13, 2022 09:40
NER dataset creator
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)
@danielhfrank
danielhfrank / pydantic.py
Created December 1, 2020 00:15
Pydantic with Numpy
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')
@dmontagu
dmontagu / fastapi_cbv.py
Last active November 24, 2024 09:20
FastAPI CBV
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__"
@smilzo
smilzo / opnsense-vpn.cfg
Last active April 12, 2024 08:23
Fritzbox VPN configuration with OPNSense
// 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
@tshirtman
tshirtman / utils.py
Last active January 19, 2021 00:21
A function to load kv files automatically.
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)