Skip to content

Instantly share code, notes, and snippets.

Organizing FastHTML Applications Across Multiple Files

Let's explore two main approaches to splitting FastHTML applications into multiple files: using Mount and using APIRouter. I'll explain the pros and cons of each and provide practical examples.

1. Using Mount - The "Mini-Apps" Approach

Mount is ideal when you want to create semi-independent sub-applications that could potentially be reused across different projects. Think of these as "mini-apps" that handle specific features.

# blog/routes.py
@cferdinandi
cferdinandi / stop-video.js
Last active February 9, 2025 16:57
A simple method to stop YouTube, Vimeo, and HTML5 videos from playing.
/**
* Stop an iframe or HTML5 <video> from playing
* @param {Element} element The element that contains the video
*/
var stopVideo = function ( element ) {
var iframe = element.querySelector( 'iframe');
var video = element.querySelector( 'video' );
if ( iframe ) {
var iframeSrc = iframe.src;
iframe.src = iframeSrc;
@jph00
jph00 / hbr-questions.md
Created September 28, 2024 14:38
The Surprising Power of Questions - HBR

The Surprising Power of Questions

It goes far beyond exchanging information.

by

  • Alison Wood Brooks
  • Leslie K. John

From Harvard Business Review Magazine (May–June 2018)

@demoive
demoive / supplant.js
Last active February 9, 2025 16:56
Variable substitution on a string. Modified from Douglas Crockford's to use {{double curly braces}}.
/**
* Variable substitution on a string.
*
* Scans through a string looking for expressions enclosed within double curly braces.
* If an expression is found, use it as a key on the object,
* and if the key has a string or number value,
* it is substituted for the bracket expression and it repeats.
*
* Originally by Douglas Crockford: http://javascript.crockford.com/remedial.html
*/
@jph00
jph00 / pathos.md
Last active February 9, 2025 16:56
Explaining Pathos in Ancient Epics and today: Claude Conversation

Explaining Pathos in Ancient Epics and today

🧑 human (Sep 21, 2024, 06:13 PM)

What is pathos, and what's it got to do with Virgil or Homer? Explain for a 12 y.o.

🤖 assistant (Sep 21, 2024, 06:13 PM)

Pathos is a way of making people feel emotions when they read or hear something. It's like when a story makes you feel sad, happy, or excited.

Virgil and Homer were famous ancient Greek and Roman poets who wrote epic stories. They used pathos a lot in their writing to make readers really care about what was happening.

For example:

function PrimeNumberGenerator() {
this.indx = 2;
}
PrimeNumberGenerator.prototype.next = function () {
var counter = 2;
while (counter < this.indx) {
if (this.indx % counter++ === 0) {
counter = 2;
@n1snt
n1snt / Oh my ZSH with zsh-autosuggestions zsh-syntax-highlighting zsh-fast-syntax-highlighting and zsh-autocomplete.md
Last active February 9, 2025 16:55
Oh my ZSH with zsh-autosuggestions zsh-syntax-highlighting zsh-fast-syntax-highlighting and zsh-autocomplete.md

Oh my zsh.

Oh My Zsh

Install ZSH.

sudo apt install zsh-autosuggestions zsh-syntax-highlighting zsh

Install Oh my ZSH.

[
{
"bindings": {
// Built-in
"ctrl-g": "menu::Cancel",
"ctrl-x 5 2": "workspace::NewWindow",
"ctrl-x ctrl-c": "zed::Quit",
"ctrl-x ctrl-f": "workspace::Open",
"ctrl-x k": "pane::CloseActiveItem",
"ctrl-x o": "workspace::ActivateNextPane",
@WaffleSmacker
WaffleSmacker / ironmario-rules.md
Last active February 9, 2025 16:54
IronMario Rules

IronMario

IronMario is a Super Mario 64 challenge created by DGR_Dave.

Based on the SM64 Randomizer. Credits: Arthurtilly, JoshDuMan, Kaze, nim.

Inspired by the brutal difficulty of challenges like IronMon, created by iateyourpie, IronMario pushes players to their limits by combining extreme randomization with a no-damage rule.

If you do create other offshoots/rules of this challenge, please make sure to shout out this challenge.

const fs = require ('fs');
const path = require ('path');
const sqlite = require ('sqlite-sync');
sqlite.connect ('./event_db_index00');
const records = sqlite.run ('SELECT trigger_time AS timestamp, file_no AS filenumber, info_start_offset AS offset, info_len AS header FROM TimingCaptureTB');
sqlite.close ();
console.log (records.length);