Skip to content

Instantly share code, notes, and snippets.

View blueswen's full-sized avatar

Blueswen blueswen

View GitHub Profile
@blueswen
blueswen / override_custom_dir_plugin.py
Last active July 9, 2022 07:22
MkDocs plugin example to adding custom directory dynamically or overriding specific template for a theme. Thanks for @squidfunk and @oprypin help.
import os
import pathlib
from mkdocs.plugins import BasePlugin
base_path = os.path.dirname(os.path.abspath(__file__))
custom_dir = os.path.join(base_path, 'custom_dir')
# there are some templates in package's custom_dir we want to use to override theme template
# Approach 1: Simulate https://github.com/mkdocs/mkdocs/blob/82bd8ba5ff177347d094b095bd623a85aaa4c80f/mkdocs/theme.py#L42
# to update theme dirs at begging
@blueswen
blueswen / instrumentor.py
Last active May 6, 2022 17:04
OpenTelemetry FastAPI Instrumentation workaround for disable internal span through custom middleware. Credit @nils-borrmann-y42 https://github.com/open-telemetry/opentelemetry-python-contrib/issues/831#issuecomment-1116225314
# Code from open-telemetry/opentelemetry-python-contrib v30.b1
# https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py
# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@blueswen
blueswen / twd_to_wgs.py
Created November 25, 2020 12:54
Python version of TWD97TM2toWGS84 Reference: https://github.com/snexuz/TWD97TM2toWGS84
import math
def twd_to_wgs(coord_x, coord_y):
# coord_x: TWD97橫座標, 南北緯度, latitude N
# coord_y: TWD97縱座標, 東西經度, longitude E
a = 6378137.0
b = 6356752.314245
lon0 = 121 * math.pi / 180