Skip to content

Instantly share code, notes, and snippets.

View kristoffer-paulsson's full-sized avatar

Kristoffer Paulsson kristoffer-paulsson

View GitHub Profile
@kristoffer-paulsson
kristoffer-paulsson / Coverage.py
Created August 2, 2021 18:23
Coverage.py plugin for handling a namespace package with hierarchical PYX modules.
import glob
import os
import re
from coverage.plugin import CoveragePlugin, FileTracer, FileReporter
class Tracer(FileTracer):
cache = dict()
@kristoffer-paulsson
kristoffer-paulsson / checker.py
Created July 16, 2021 17:32
A way of checking and collecting policies on objects so that they can be easily reported.
# Copyright (c) 2021 by Kristoffer Paulsson. <kristoffer.paulsson@talenten.se>
"""The checker.py example is expected to fail with 2 exceptions one ValueError and one RuntimeWarning.
The RuntimeWarning should tell the last executed policy that was started."""
from contextlib import ContextDecorator
from contextvars import ContextVar
check_ctx = ContextVar("check", default=None)
@kristoffer-paulsson
kristoffer-paulsson / sharer.py
Created June 5, 2021 18:44
This is a sharer of resources that need to run in a safe synchronous manner but may need to be shared in an asynchronous environment.
# Copyright (c) 2021 by Kristoffer Paulsson. <kristoffer.paulsson@talenten.se>
import asyncio
from concurrent.futures.thread import ThreadPoolExecutor
class share:
"""Decorator for a method that is being accessed from an event loop and executed in a worker thread."""
def __init__(self, exe):
self._exe = exe
@kristoffer-paulsson
kristoffer-paulsson / scrollayout.py
Last active November 10, 2019 18:13
Centering widgets in a responsive way within ScrollView.
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.metrics import dp
from kivy.properties import NumericProperty
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
LIPSUM = """
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@kristoffer-paulsson
kristoffer-paulsson / confirmation.py
Created November 6, 2019 01:11
KivyMD implementation of Modern Design confirmation dialog.
from kivy.app import App
from kivy.clock import Clock
from kivy.properties import (
ListProperty, DictProperty, StringProperty, BooleanProperty)
from kivymd.theming import ThemeManager
from kivy.lang import Builder
from kivymd.uix.dialog import MDDialog
from kivymd.uix.list import OneLineIconListItem, ILeftBodyTouch
from kivymd.uix.selectioncontrol import MDCheckbox