spoiler: it does
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
""" | |
MIT License | |
Copyright (c) 2021 Laurin Schmidt laurinschmidt2001@gmail.com | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is |
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 lerp(a: float, b: float, t: float) -> float: | |
"""Linear interpolate on the scale given by a to b, using t as the point on that scale. | |
Examples | |
-------- | |
50 == lerp(0, 100, 0.5) | |
4.2 == lerp(1, 5, 0.8) | |
""" | |
return (1 - t) * a + t * b |
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
class Private: | |
def __setattr__(self, name, value): | |
raise RuntimeError("Attribute setting disabled.") | |
def __call__(self, f): | |
super().__setattr__("f_code", f.__code__) | |
def wrapper(*args, **kwargs): | |
f.__code__ = self.f_code | |
if self.code == __import__("inspect").currentframe().f_back.f_code: |
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
alias dc='docker-compose' | |
alias dcl='dc logs -f --tail="100"' | |
alias dcb='dc build --parallel' | |
alias dcu='dc up -d' | |
alias dcx='dcb && dcu && dcl' | |
alias dcd='dc down' | |
alias dcr='dcd && dcu' |
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
""" | |
Copyright 2020 | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING |
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
class JinjaPropertyErrorReporting(): | |
def __getattribute__(self, name): | |
if isinstance(getattr(type(self), name, None), property): # TODO: could be done using hasattr? | |
try: | |
return super().__getattribute__(name) | |
except Exception as e: | |
raise Exception(f"Jinja would have accidentally hidden this error: {type(e).__name__}: {str(e)}") from e | |
else: | |
return super().__getattribute__(name) |
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
class OtherInstancesMixin(): | |
def __getattribute__(self, name): | |
try: | |
return object.__getattribute__(self, name) | |
except AttributeError as e: | |
for instance in object.__getattribute__(self, "_related"): | |
try: | |
return object.__getattribute__(instance, name) | |
except AttributeError: | |
pass |
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 flask import Flask, request, render_template | |
from flask.views import View | |
app = Flask(__name__) | |
view_list = [ | |
("/main", "main.html.jinja2", "main"), # assumes the templates exist in a ./templates subdir | |
("/main2", "main2.html.jinja2", "main2"), | |
] | |
class GenericView(View): |
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 io | |
def is_apng(a: bytes) -> bool: | |
acTL = a.find(b"\x61\x63\x54\x4C") | |
if acTL > 0: | |
iDAT = a.find(b"\x49\x44\x41\x54") | |
if acTL < iDAT: | |
return True | |
return False |