A collection of FizzBuzz implementations in python I've written and/or collected over the years. No need to comment that most of these are silly, I'm well aware and this is intentional.
This file contains hidden or 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 datetime import datetime, timezone | |
non_naive_timestamp = datetime.now(timezone.utc) | |
iso_timestamp = non_naive_timestamp.isoformat("T") + "Z" | |
filename_safe_timestamp = f"{non_naive_timestamp:%Y%m%d-%H%M%S%Z}" |
This file contains hidden or 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 inspect import signature, Parameter | |
from typing import Annotated, Callable, get_origin | |
# Incomplete, should import jsonschema | |
python_to_json_schema_types = { | |
str: "string", | |
int: "integer", | |
float: "number", | |
bool: "boolean", |
This file contains hidden or 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 PIL import Image, ImageFilter | |
def drop_shadow(layer, color="#000", radius=0, distance=0): | |
radius = radius or layer.size[0] // 64 | |
distance = distance or layer.size[0] // 64 | |
shadow = Image.new(layer.mode, layer.size, color=color) | |
shadow.putalpha(layer.effect_spread(distance).getchannel('A')) |
This file contains hidden or 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 csv | |
class Invisible(csv.Dialect): | |
delimiter = chr(0x1f) # US | |
escapechar = None | |
lineterminator = chr(0x1e) # RS | |
quoting = csv.QUOTE_NONE | |
This file contains hidden or 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
blueprint: | |
name: iluminize ZG2819S-RGBW | |
source_url: https://gist.github.com/djoek/ddabd8c94057a86aad1734e0ab513886/raw/bee58d171bc79b7151a65456cc7da670646282c7/iluminize.yaml | |
description: Control lights with a iluminize 511.344 RGBW Remote | |
domain: automation | |
input: | |
remote: | |
name: Remote | |
description: iluminize 511.344 remote to use | |
selector: |
This file contains hidden or 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 functools import wraps | |
def memoized_property(fget): | |
attr_name = '_{0}'.format(fget.__name__) | |
@wraps(fget) | |
def fget_memoized(self): | |
if not hasattr(self, attr_name): | |
setattr(self, attr_name, fget(self)) |
This file contains hidden or 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
.progress-donut { | |
background: conic-gradient( | |
from -135deg, | |
rgba(255, 0, 0, 1.0) 80deg, /* change me for value set */ | |
rgba(255, 0, 0, 0.3) 0deg 270deg, | |
rgba(255, 0, 0, 0.0) 270deg | |
); | |
mask-image: radial-gradient( | |
rgba(0, 0, 0, 0) 25%, | |
rgba(0, 0, 0, 1) 25%, |
This file contains hidden or 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 typing import Union, Awaitable, AsyncIterable | |
def aiter(o: Union[AsyncIterable, Awaitable], sentinel=None): | |
if isinstance(o, AsyncIterable): | |
async for item in o: | |
yield item | |
elif isinstance(o, Awaitable): | |
while True: | |
val = await o | |
if (sentinel is None and val is sentinel) or val == sentinel: |
This file contains hidden or 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 numpy import arange, ceil, sqrt | |
candidates = arange(100) | |
candidates[1] = 0 # 1 is not a prime | |
upto = ceil(sqrt(candidates.size)).astype(candidates.dtype) | |
for c in candidates[2:upto]: | |
candidates[2*c::c].fill(0) if c else ... | |
print(candidates[candidates > 0]) |
NewerOlder