Skip to content

Instantly share code, notes, and snippets.

View pauleveritt's full-sized avatar

Paul Everitt pauleveritt

View GitHub Profile
@pauleveritt
pauleveritt / site.test.js
Created April 17, 2024 17:40
11ty constructor, options, dirs
test("should load an Eleventy site", async () => {
const elev = new Eleventy("./", "./_site", {
dir: {
includes: "my_includes",
layouts: "my_layouts",
},
});
await elev.init();
const d = elev.config.dir;
expect(elev.config.dir.includes).toEqual("my_includes");
@pauleveritt
pauleveritt / memoize2.py
Created November 12, 2023 20:25
Series of examples gradually building up a memoize example.
from __future__ import annotations
from typing import Any
from tagstr import Thunk
from tagstr.memoize import TagStringArgs, TagStringCallable
def immutable_bits(*args: str | Thunk) -> tuple[str | tuple[Any], ...]:
bits = []
for arg in args:
@pauleveritt
pauleveritt / foo.test.tsx
Created May 5, 2023 17:31
Try to get `this` into a layout view.
import type { FunctionComponent, VNode } from "preact";
import { createContext, render as preactRender } from "preact";
import { expect, test } from "vitest";
export type EleventyContext = {
siteTitle: string;
};
const Context = createContext<EleventyContext | null>(null);
<h1>Hello Animals</h1>
<ng-container *ngIf="isFish(pet)">
<button (click)="pet.swim()">Swim!</button>
</ng-container>
<ng-container *ngIf="isFish(pet)">
<button (click)="pet.fly()">Fly!</button>
</ng-container>
@pauleveritt
pauleveritt / scratch.html
Created September 25, 2022 20:56
Idiomorph with a custom element.
<html>
<head>
<title>Custom Element Morph</title>
<script src="https://unpkg.com/idiomorph"></script>
</head>
<body>
<hello-world name="World"></hello-world>
<button id="update">Update</button>
<script defer>
class HelloWorld extends HTMLElement {
@pauleveritt
pauleveritt / custom_elements.html
Created September 25, 2022 20:56
Use of idiomorph with a custom element.
Idiomorph.morph(target, newHTML, {morphStyle: 'innerHTML'});
@pauleveritt
pauleveritt / scratchpad.py
Created August 4, 2021 08:21
Broken example of a protocol registry
"""A broken attempt at a Protocol-based registry.
I have a system with replaceable implementations. A ``Heading``
might be asked for on a page, but which one you get depends
on some criteria.
mypy doesn't seem to like using Protocols at runtime. This
small module has 7 errors.
"""
from dataclasses import dataclass
from dataclasses import dataclass
from typing import Protocol, Optional, TypeVar, Type
class Animal(Protocol):
name: str
@dataclass
class Mammal:
@pauleveritt
pauleveritt / pathlib_static.py
Created November 17, 2020 23:39
How to re-parent an absolute path to be under a different root?
from pathlib import Path
def main():
icon = Path('/favicon.png')
static = Path('/static')
result = static / icon
print(str(result))
@pauleveritt
pauleveritt / injector.py
Last active September 15, 2020 23:22
Using an alias for a PEP 593 Annotation with multiple arguments.
"""
Using an alias for a PEP 593 Annotation with multiple arguments.
I'm rewriting my injector.
I currently put the injector information in dataclass field metadata.
I'd like to allow other callables such as functions, so I'm looking at PEP 593 Annotations, similar to what [the inject package](https://github.com/alecthomas/injector/blob/master/injector/__init__.py#L1116) does.
My injection though needs zero or more arguments, sort of like an RxPY pipeline.
# Update 1: Changed from Markdown science fiction to using code in a running test