Skip to content

Instantly share code, notes, and snippets.

View pauleveritt's full-sized avatar

Paul Everitt pauleveritt

  • JetBrains
  • Fredericksburg, VA
View GitHub Profile
@pauleveritt
pauleveritt / looping.py
Created April 8, 2020 22:11
Subcomponents and looping
def TodoItem(item):
return html('<li>{item}</li>')
def Todo(todos):
items = [
html('<{TodoItem} item={item}/>')
for item in todos
]
return html('<div><h1>Todos</h1><ul>{items}</ul></div>')
@pauleveritt
pauleveritt / gatsby-node.js
Created October 18, 2019 15:46
GatsbyJS Schema Customization to add a type directive
/*
I want to make a custom type directive (or is it extension? I've seen both terms used.)
Unfortunately the "extend" never gets called. I think createFieldExtension is the
wrong thing to use. But I don't know how to grab the schemaComposer instance and
call addDirective.
I'm hoping to use it this way:
type Author implements Node & Resource @metadata(plural: "Authors") {
@pauleveritt
pauleveritt / gatsby-node.js
Created October 10, 2019 14:26
Rewrite of Chris Biscardi's onCreateNode function for tutorial
/*
From the tutorial at:
https://www.christopherbiscardi.com/post/constructing-query-types-in-themes/
*/
async function onCreateNode(
{
actions,
node,
@pauleveritt
pauleveritt / render.py
Created October 6, 2019 22:24
Rendering htm templates in a dataclass
# htm: omit-self-in-dataclass
from dataclasses import dataclass
from htm import htm
@htm
def html(tag, props, children):
return tag, props, children
@dataclass
# Part of my vacation work was React-style "components" for Sphinx themes. For
# example, you'd get a breadcrumb in your Jinja2 via:
#
# {{ Breadcrumb (arg1=value1) }}
#
# and breadcrumb is a "Component" whose constructor is made available in the
# Jinja2 context.
#
# I'd like a decorator:
@pauleveritt
pauleveritt / decorator.py
Created March 26, 2019 22:16
Venusian decorator as a class with a wrapper
# This decorator
class singleton:
def __init__(self,
for_=None,
context=None,
name: str = None,
):
self.for_ = for_
self.context = context if context else for_
self.name = name
@pauleveritt
pauleveritt / test_sample.py
Created March 23, 2019 00:39
Sample app for wired
"""
Simple application to demonstrate wired.
- A Greeter gives a greeting
- There are two kinds of greeters: Greeter and PyramidGreeter
- Use PyramidGreeter when the context is a PyramidCustomer
- A greeter will give a different greeting if the system is
set to use French
- The settings are a singleton service
@pauleveritt
pauleveritt / python_ssr.md
Last active June 3, 2022 07:52
LitElement and Python SSR

Filed under "it's likely hopeless, but..."

I'm beginning an exploration of LitElement and web components. I've been heavy in Angular, React, Gatsby, and HyperApp. Since I'm currently deep in Gatsby, I'm thinking about SSR, PRPL, and "first render".

More specifically, I come from Python. It's hard if you're not running Node on the server and get SSR and first render. This document talks about it.

@pauleveritt
pauleveritt / gatsby_thoughts.md
Created January 18, 2019 00:16
Thoughts on Gatsby

build vs. develop vs. ???

Let's say you're doing a blog in Markdown. You have content authors doing Markdown stuff. All good. They create stuff and get a great, fast authoring experience.

Until you get a lot of content. Solution #1: move stuff out of page queries, over to sourceNodes. Which works great, unless one piece of content depends on another. sourceNodes doesn't get re-run on changes. Anything you do in fields, has to happen at startup. I wind up blowing away my cache multiple times a day, as an author.

def test_subcomponent_field():
# See if value in parent field makes it through
@dataclass
class Component:
template: str = 'component.html'
name: str = 'Component'
@dataclass
class Sub:
name: str