Skip to content

Instantly share code, notes, and snippets.

View bartkl's full-sized avatar

Bart Kleijngeld bartkl

View GitHub Profile
@bartkl
bartkl / backend.py
Last active May 10, 2024 19:29
Streaming JSON chunks (FastAPI <-> fetchAPI)
# FastAPI.
async def stream_json_list(items):
for item in items:
yield item
await asyncio.sleep(4.0) # To demonstrate, visibly, the successful implementation.
async def get_media_metadata(tags: Optional[Set[str]] = Query(None,
description="Tags to filter on")):
@bartkl
bartkl / unzip.py
Created December 17, 2020 10:16
unzip.py
import itertools
def unzip(in_: Iterable[Tuple[Any, ...]]) -> Iterable[Tuple[Any, ...]]:
"""Unzips a N-sized iterable of M-tuples to a M-sized iterable of N-tuples.
Example:
>>> data = [('a', 'b', 'c'), (1, 2, 3)] # 2x3
>>> unzip(data) == [('a', 1), ('b', 2), ('c', 3)] # 3x2
True
@bartkl
bartkl / darkmode.inline.ts.diff
Created January 21, 2024 19:11
Quartz Excalidraw render
diff --git a/quartz/components/scripts/darkmode.inline.ts b/quartz/components/scripts/darkmode.inline.ts
index c42a367..06767b5 100644
--- a/quartz/components/scripts/darkmode.inline.ts
+++ b/quartz/components/scripts/darkmode.inline.ts
@@ -1,5 +1,6 @@
-const userPref = window.matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark"
-const currentTheme = localStorage.getItem("theme") ?? userPref
+import { getUserPreferredColorScheme, renderExcalidrawLinks } from "./util"
+
+const currentTheme = localStorage.getItem("theme") ?? getUserPreferredColorScheme()