Skip to content

Instantly share code, notes, and snippets.

View dgwyer's full-sized avatar
🏠
Working from home

David Gwyer dgwyer

🏠
Working from home
View GitHub Profile
@dgwyer
dgwyer / fasthtml-llms-ctx.txt
Last active January 23, 2025 13:05
A manually formatted version of the raw FastHTML llms-ctx.txt file to reduce file size
<project title="FastHTML" summary='FastHTML is a python library which brings together Starlette, Uvicorn, HTMX, and fastcore&#39;s `FT` "FastTags" into a library for creating server-rendered hypermedia applications. The `FastHTML` class itself inherits from `Starlette`, and adds decorator-based routing with many additions, Beforeware, automatic `FT` to HTML rendering, and much more.'>Things to remember when writing FastHTML apps:
- Although parts of its API are inspired by FastAPI, it is *not* compatible with FastAPI syntax and is not targeted at creating API services
- FastHTML includes support for Pico CSS and the fastlite sqlite library, although using both are optional; sqlalchemy can be used directly or via the fastsql library, and any CSS framework can be used. Support for the Surreal and css-scope-inline libraries are also included, but both are optional
- FastHTML is compatible with JS-native web components and any vanilla JS library, but not with React, Vue, or Svelte
- Use `serve()` for running uvi
@dgwyer
dgwyer / action-types.js
Created September 28, 2023 15:00 — forked from helgatheviking/action-types.js
Product Data Store Example
const TYPES = {
FETCH_FROM_API : "FETCH_FROM_API",
HYDRATE_PRODUCT: "HYDRATE_PRODUCT",
};
export default TYPES;
/**
* WordPress dependencies
*/
import { createReduxStore, register, controls } from '@wordpress/data';
import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';
export const STORE_NAME = 'search-filter/settings';
const getUniqueKey = ( args ) => {
@dgwyer
dgwyer / index.js
Last active August 30, 2023 15:42
import { registerPlugin } from "@wordpress/plugins";
import { useState, useEffect, createPortal } from "@wordpress/element";
const SomeEditorPlugin = () => {
const [portalContainer, setPortalContainer] = useState(null);
useEffect(() => {
// Wait for the DOM element to be available
const container = document.querySelector("#some-element");
setPortalContainer(container);
@dgwyer
dgwyer / error-log.txt
Last active August 17, 2023 12:53
Test script run via a GitHb action to create InstaWP sites
Attempting to create site 1 of 10...
Site name: 1234-test-3B9gNalUoA
Sites created: Promise { <pending> }
New site created: {
status: true,
message: 'Site installation work in progress, Wait for installation.',
data: {
message: 'Site installation work in progress, Wait for installation.',
task_id: 'b037e201ddc9',
status: 1,
#!/bin/bash
# Number of posts to create
posts=100
# Paragraphs
p=2
# Create new posts and pages with random Lorem ipsum content inside paragraph blocks
curl -N http://loripsum.net/api/$p | sed '/^$/d' | sed 's/^/<\!-- wp:paragraph -->/' | sed 's/$/<\!-- \/wp:paragraph -->/' | wp post generate --count=$posts --post_content
#!/bin/bash
# Delete all posts for specified posts types
wp post delete $(wp post list --post_type='post,page,product,attachment' --format=ids) --force
#!/bin/bash
# Start the timer
start_time=$(date +%s)
# Vars
import_images=12
# 1. IMPORT MEDIA
import fs from 'fs';
import needle from 'needle';
import cryptojs from 'crypto-js';
import config from '../../../../caller/deploy.config.js';
export function deployZip() {
// Base 64 URL encode.
const base64_url_encode = function (str) {
str = Buffer.from(str).toString('base64');
str = str.replace(/=/g, '');
@dgwyer
dgwyer / what-forces-layout.md
Created October 19, 2022 14:00 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent