Skip to content

Instantly share code, notes, and snippets.

from fasthtml.common import *
from fastlite import *
from dataclasses import dataclass
from typing import Optional
# Initialize FastHTML app with PicoCSS and SQLite database
db = database('data/users.db')
app, rt = fast_app(pico=True)
# Define User dataclass for form data
from enum import Enum
from functools import singledispatch
class Color(Enum):
RED = 1
GREEN = 2
BLUE = 3
@singledispatch
def process(color: Color, *args, **kwargs):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Layout</title>
<style>
body {
margin: 0;
padding: 0;
List of elements
Element Description Categories Parents† Children Attributes Interface
a Hyperlink flow; phrasing*; interactive; palpable phrasing transparent* globals; href; target; download; ping; rel; hreflang; type; referrerpolicy HTMLAnchorElement
abbr Abbreviation flow; phrasing; palpable phrasing phrasing globals HTMLElement
address Contact information for a page or article element flow; palpable flow flow* globals HTMLElement
area Hyperlink or dead area on an image map flow; phrasing phrasing* empty globals; alt; coords; shape; href; target; download; ping; rel; referrerpolicy HTMLAreaElement
article Self-contained syndicatable or reusable composition flow; sectioning; palpable flow flow globals HTMLElement
aside Sidebar for tangentially related content flow; sectioning; palpable flow flow globals HTMLElement
audio Audio player flow; phrasing; embedded; interactive; palpable* phrasing source*; track*; transparent* globals; src; crossorigin; preload; autoplay; loop; muted; controls HTMLAudioElement
{
"*": {
"attributes": {
"accesskey": {
"experimental": false
},
"anchor": {
"experimental": true
},
"autocapitalize": {
import colorsys
def hex_to_rgb(hex_color):
# Remove the '#' if present
hex_color = hex_color.lstrip('#')
return tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
def calculate_luminance(hex_color):
# Convert hex to RGB
r, g, b = hex_to_rgb(hex_color)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Drag and Drop with JS</title>
<style>
body {
margin: 2em;
font-family: 'arial';
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML5 Modal Dialog Example</title>
<style>
/* Modal styles */
.modal {
display: none;
from math import log10
from typing import Sequence
def print_numbered_list(items: Sequence, fmt='{num}. {item}') -> None:
"""Display as a numbered list where the items are left aligned.
items:
A list of printable items.
fmt:
@bpeterso2000
bpeterso2000 / print_table.py
Last active February 18, 2023 02:25
Display a list of lists as a simple text table with rows, columns and an optional header.
from math import log10
from typing import Sequence
def print_table(rows: Sequence[Sequence], hdr=True, rownums=True) -> None:
"""Display as a simple text table; rows, columns & optional header.
rows:
Rows & columns where each cell object is a string or can be
converted into a string.