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
#!/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
# 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
@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,
@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);
/**
* 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 / 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;
@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 / serve.py
Created January 25, 2025 15:13
Custom FastHTML server() function for development
from fasthtml.common import *
import subprocess
def serve_dev(
app='app',
host='0.0.0.0',
port=None,
reload=True,
reload_includes=None,
reload_excludes=None,
@dgwyer
dgwyer / settings.json
Last active January 27, 2025 17:37
VS Code settings for FastHTML Pythin intellisense
{
"tailwindCSS.includeLanguages": {
"python": "html",
},
"tailwindCSS.experimental.classRegex": [
"\\b[a-zA-Z_]+\\s*=\\s*['\"]([^'\"]*)['\"]",
"\"[^\"]+\"\\s*:\\s*\"([^\"]*)\"",
"'[^']+'\\s*:\\s*'([^']*)'"
]
}
@dgwyer
dgwyer / db.py
Created February 24, 2025 14:27
Audio Anki Cards
import sqlite3
# Create the SQLite database
def create_sql_questions_database():
# Connect to SQLite database (creates it if it doesn't exist)
conn = sqlite3.connect('sql_questions.db')
cursor = conn.cursor()
# Create table with auto-incrementing ID and question field
cursor.execute('''