Skip to content

Instantly share code, notes, and snippets.

View thmsklngr's full-sized avatar

Thomas Klinger thmsklngr

View GitHub Profile
@thmsklngr
thmsklngr / attrs_set_other_attributes.py
Created September 13, 2022 09:51
python-attrs - setting other attributes when one attribute is set
def _set_y(instance, attribute, value):
object.__setattr_(instance, 'y', value)
# returning a value is important, otherwise attribute will become None
return value
@define
class MyClass:
x: str = field(on_settattr=[_set_y])
y: str = field()
@thmsklngr
thmsklngr / doruk.mustache
Created November 19, 2020 19:50
VSCode autodocstring template with alternative (and easy to read) syntax
{{! Template according https://dorukkilitcioglu.com/2018/08/18/python-better-docstring.html }}
{{! Doruk Docstring Template }}
{{summaryPlaceholder}}
{{extendedSummaryPlaceholder}}
{{#argsExist}}
Args:
{{#args}}
{{&var}}::{{&typePlaceholder}}
@thmsklngr
thmsklngr / ponyorm.py
Created November 4, 2020 15:12
Comparing PonyORM and Peewee with a simple example (using UUID4 as primary key) - ponyorm.py
import string
import secrets
from pony import orm
import uuid
database_settings = {
'host': 'localhost',
'user': 'ponyorm',
'password': 'ponyorm',
'database': 'ponyorm'
@thmsklngr
thmsklngr / peewee.py
Last active November 4, 2020 15:09
Comparing PonyORM and Peewee with a simple example (using UUID4 as primary key) - peewee.py
import string
import secrets
import peewee as pw
import uuid
database_settings = {
'host': 'localhost',
'user': 'peewee',
'password': 'peewee'
}