Posts tagged: webdev

All posts with the tag "webdev"

214 posts latest post 2026-07-05
Publishing rhythm
Jun 2026 | 2 posts
Show some equivalent list comprehensions in filter examples · Issue #1068 · pallets/jinja I'm willing to write a pull-request for this, but I just want to see what people think before I write it. So the issue is this. I'm very familiar with python. I'm new to Jinja2. Often I find myself... GitHub · github.com [1] I often want to reach for non existing list comprehensions in jinja 2, Here are a few nice equivalents. a: {{ data | selectattr('x', 'gt', 5) | list }} b: {{ data | map(attribute='c') | list }} c: {{ data | selectattr('x', 'gt', 5) | map(attribute='c') | list }} References: [1]: https://github.com/pallets/jinja/issues/1068

I am working on fokais.com’s signup page, and I want to hide the form input during an htmx request. I was seeing some issues where I was able to prevent spamming the submit button, but was still able to get one extra hit on it.

It also felt like nothing was happening while sending the email to the user for verification. Now I get the form to disappear and a spinner to show during the request.

html">HTML #

Let’s start off with the form. It uses htmx to submit a post request to the post_request route. Note that there is a spinner in the post_request with the htmx-indicator class.

The intent is to hide the spinner until the request is running, and hide all of the form input during the request.

<form
  id="signup-form"
  hx-swap-oob="outerHTML"
  class="m-4 mx-auto mb-6 flex w-80 flex-col rounded-lg b p-4 shadow-xlc shadow-cyan-500/10"
  method="POST"
  action="{{ url_for('post_signup') }}"
  hx-post="{{ url_for('post_signup') }}"
>

<!--markata-attribution-->
  <input
    class="mx-8 mt-6 mb-4 border border-black bg-zinc-900 p-1 text-center focus:bg-zinc-800"

<!--markata-attribution-->
    type="text"

<!--markata-attribution-->
    value="{{ full_name }}"

<!--markata-attribution-->
    name="full_name"

<!--markata-attribution-->
    placeholder="Full Name"
  />

<!--markata-attribution-->
  {% if full_name_error %}

<!--markata-attribution-->
  <label class="-mt-6 mb-6 mx-8 text-red-500 p-1 text-center">

<!--markata-attribution-->
    {{ full_name_error }}

<!--markata-attribution-->
  </label>

<!--markata-attribution-->
  {% endif %}

<!--markata-attribution-->
  <input
    class="mx-8 mb-4 border border-black bg-zinc-900 p-1 text-center focus:bg-zinc-800"

<!--markata-attribution-->
    type="text"

<!--markata-attribution-->
    value="{{ username }}"

<!--markata-attribution-->
    name="username"

<!--markata-attribution-->
    placeholder="username"
  />

<!--markata-attribution-->
  {% if username_error %}

<!--markata-attribution-->
  <label class="-mt-6 mb-6 mx-8 text-red-500 p-1 text-center">

<!--markata-attribution-->
    {{ username_error }}

<!--markata-attribution-->
  </label>

<!--markata-attribution-->
  {% endif %}

<!--markata-attribution-->
  <input
    class="mx-8 mb-4 border border-black bg-zinc-900 p-1 text-center focus:bg-zinc-800"

<!--markata-attribution-->
    type="email"

<!--markata-attribution-->
    name="email"

<!--markata-attribution-->
    value="{{ email }}"

<!--markata-attribution-->
    placeholder="email"
  />

<!--markata-attribution-->
  {% if email_error %}

<!--markata-attribution-->
  <label class="-mt-6 mb-6 mx-8 text-red-500 p-1 text-center">

<!--markata-attribution-->
    {{ email_error }}

<!--markata-attribution-->
  </label>

<!--markata-attribution-->
  {% endif %}

<!--markata-attribution-->
  <input
    class="mx-auto w-32 mb-4 border border-black bg-purple-900 p-1 text-center focus:bg-zinc-800"

<!--markata-attribution-->
    type="submit"

<!--markata-attribution-->
    value="sign up"
  />

<!--markata-attribution-->
  <div role="status" class="mx-auto htmx-indicator">

<!--markata-attribution-->
    <svg

<!--markata-attribution-->
      class="mx-auto animate-spin h-5 w-5 text-white"

<!--markata-attribution-->
      xmlns="https://www.w3.org/2000/svg"

<!--markata-attribution-->
      fill="none"

<!--markata-attribution-->
      viewBox="0 0 24 24"
    >

<!--markata-attribution-->
      <circle

<!--markata-attribution-->
        class="opacity-25"

<!--markata-attribution-->
        cx="12"

<!--markata-attribution-->
        cy="12"

<!--markata-attribution-->
        r="10"

<!--markata-attribution-->
        stroke="currentColor"

<!--markata-attribution-->
        stroke-width="4"
      ></circle>

<!--markata-attribution-->
      <path

<!--markata-attribution-->
        class="opacity-75"

<!--markata-attribution-->
        fill="currentColor"
        d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
      ></path>

<!--markata-attribution-->
    </svg>

<!--markata-attribution-->
    <p>Signing up...</p>

<!--markata-attribution-->
  </div>

<!--markata-attribution-->
</form>

Yes this is styled using tailwindcss.

https://waylonwalker.com/still-loving-tailwind/

CSS #

Let’s take a look at how we achieve switching between only spinner an only form inputs using css.

.htmx-indicator {
  @apply hidden;
  opacity: 0;
  transition: opacity 500ms ease-in;
}
.htmx-request button,
.htmx-request input[type="submit"],
.htmx-request input,
.htmx-request label {
  @apply hidden;
}
.htmx-request .htmx-indicator {
  opacity: 1;
  @apply block;
}
.htmx-request.htmx-indicator {
  opacity: 1;
  @apply block;
}

Final Result #

Here is the final result of me signing up for a new account in fokais.

Adam Wathan (@adamwathan) on X Hear me out. X (formerly Twitter) · twitter.com [1] I’m going to give this trick a shot on my sites, and see how I like it. * { min-width: 0 } Down in the comments @adamwathan [2] goes on to say. Basically every layout overflow bug ever boils down to some flex or grid child needing min-width: 0 😄 Oh and @ryanflorence [3] also says in the comments. I … do this. References: [1]: https://twitter.com/adamwathan/status/1734696245015494711 [2]: https://twitter.com/adamwathan/ [3]: https://twitter.com/ryanflorence
Path Operation Advanced Configuration - FastAPI FastAPI framework, high performance, easy to learn, fast to code, ready for production fastapi.tiangolo.com [1] Excluding routes from fastapi docs, can be done from the route configuration using `include_in_schema`. This is handy for routes that are not really api based or duplicates. From the Docs # [2] from fastapi import FastAPI app = FastAPI() @app.get("/items/", include_in_schema=False) async def read_items(): return [{"item_id": "Foo"}] trailing slash # [3] I’ve had better luck just routing both naked and trailing slash routes in fastapi [4]. I’ve had api’s deployed as a subroute to a site rather than a subdomain, and the automatic redirect betweens them tended to always get messed up. This is pretty easy fix for the pain is causes just give vim a yyp, and if you don’t want deuplicates in your docs, ignore one. from fastapi import FastAPI app = FastAPI() @app.get("/items") @app.get("/items/", include_in_schema=False) async def read_items(): return [{"item_id": "Foo"}] favicon.ico # [5] Now you do not need to deploy favicons to your api in any way, it is nice to have it in your browser tab, but more importantly ...
Protect API docs behind authentication? · Issue #364 · fastapi/fastapi Basic Question Does FastAPI provide a method for implementing authentication middleware or similar on the docs themselves (e.g. to protect access to /docs and /redoc)? Additional context My company... GitHub · github.com [1] You can protect your fastapi [2] docs behind auth so that not only can certain roles not run certain routes, but they cannot even see the docs at all. This way no one that shouldn’t be poking around can even discover routes they shouldn’t be using. Here is the soluteion provided by @kennylajara [3] from fastapi import FastAPI from fastapi.openapi.docs import get_redoc_html, get_swagger_ui_html from fastapi.openapi.utils import get_openapi import secrets from fastapi import Depends, FastAPI, HTTPException, status from fastapi.security import HTTPBasic, HTTPBasicCredentials app = FastAPI( title="FastAPI", version="0.1.0", docs_url=None, redoc_url=None, openapi_url = None, ) security = HTTPBasic() def get_current_username(credentials: HTTPBasicCredentials = Depends(security)): correct_username = secrets.compare_digest(credentials.username, "user") correct_password = secrets...
Cancel subscriptions Cancel subscriptions immediately or at the end of the subscription period with proration options, invoice handling, and automatic cancellation after failed payment attempts. stripe.com [1] This is a handy guide to cancelling stripe subscriptions. # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys import stripe stripe.api_key = "sk_test_51ODvHtB26msLKqCAPBAo1qkBBuIfT5tQBX6YFWCLMsPixIExxITCRVa9tNCIqkdQS8olhR79NYXsFWBPKsM3LbGO00zEcNQfNI" stripe.Subscription.modify( "sub_49ty4767H20z6a", cancel_at_period_end=True, ) You can even inverse it by flipping True to False and re activate the subscription. References: [1]: https://stripe.com/docs/billing/subscriptions/cancel#canceling
External Link stripe.com [1] You can find your customers next billing date through the stripe api by using Invoice. and passing in customer, customer_details, subscription, or schedule. import stripe stripe.api_key = "sk_test_51ODvHtB26msLKqCAPBAo1qkBBuIfT5tQBX6YFWCLMsPixIExxITCRVa9tNCIqkdQS8olhR79NYXsFWBPKsM3LbGO00zEcNQfNI" invoice = stripe.Invoice.upcoming(customer="cus_NeZwdNtLEOXuvB") Within the invoice, you can find the next_payment_attempt as a epoch. date = datetime.fromtimestamp(invoice.next_payment_attempt) amount = invoice.amount_due currency = invoice.currency References: [1]: https://stripe.com/docs/api/invoices/upcoming
Search Use the search APIs to look up and retrieve objects in your Stripe data. Using search is a faster alternative to paginating through all resources. stripe.com [1] Stripe has it’s own query language for querying data. I’m just getting into using it and it seems pretty good so far. I needed to lookup the price for products. I was able to find prices for my product using the python api as shown below. stripe.Price.search(query="active: 'true' and product: 'prod_P8SfwtxJ45cWE2'") References: [1]: https://stripe.com/docs/search#search-query-language
stripe-keys-and-ids.tsv [1] tsv Prefix Description Notes ac_ Platform Client ID Identifier for an auth code/client id. acct_ Account ID Identifier for an Account object. aliacc_ Alipay Account ID Identifier for an Alipay account. ba_ Bank Account ID Identifier for a Bank Account object. btok_ Bank Token ID Identifier for a Bank Token object. card_ Card ID Identifier for a Card object. cbtxn_ Customer Balance Transaction ID Identifier for a Customer Balance Transaction object. ch_ Charge ID Identifier for a Charge object. cn_ Credit Note ID Identifier for a Credit Note object. cs_live_ Live Checkout Session ID Identifier for a checkout Session object in live mode. cs_test_ Test Checkout Session ID Identifier for a checkout Session object in test mode. cus_ Customer ID Identifier for a Customer object. dp_ Dispute ID Identifier for a Dispute object. evt_ Event ID Identifier for an Event object. fee_ Application Fee ID Identifier for an Application Fee object. file_ File ID Identifier for a File object. fr_ Application Fee Refund ID Identifier for an Application Fee Refund object. iauth_ Issuing Authorization ID Identifier for an Issuing Authorization object. ic_ Issuing Card ID ...

Looking for a Heroku replacement, What I found was shocking!

Your browser does not support the audio element. I’ve long hosted my personal blog as a static site on waylonwalker.com. It’s all markdown, converted to html [1], and shipped as is. It’s been great, I’ve moved it from GitHub Pages, to Netlify, tried Vercel for a minute, and have landed on Cloudflare Pages. Each migration has not really been that hard, it’s just pointing ci to a different host after the site has built. [2] What about server side # [3] Now the part that I have struggled with is how to cheaply host a server rendered application that can just live on forever without me paying for it. This is a harder problem as it costs more to keep servers spinning, memory, and disk all ready for you to use at a moments notice. Honestly # [4] I never really deployed anything that useful on heroku, but it seems like the klenex of the bunch that’s why they are in the title. I’ve moved between digital ocean and fly.io, and have had some great experiences with both. I just don’t want...

I’ve been using tailwind for a few months now and I can still say I’m loving it. I’ve been using it to create some rapid prototypes that may or may not ever become something, a document that is likely to go to print (a resume), and some quick dashboards.

I started using Tailwind a few month back #

A few months back in september of 2023 I made a case for tailwindcss. And have been using it on quite a few projects since.

  • values are well thought out
  • it’s really easy to use
  • classes that make sense
  • tree shakable

fokais.com #

I started working on fokais.com only a few weeks ago, It’s going to be a SAS to make blogging easier. I’ve started hosting some tools for this blog that I really like that I think I can turn into a service. It’s been fantastic to quickly pump out new pages with tailwind.

screenshot of https://fokais.com

htmx">HTMX #

tailwind and htmx are a match made in heaven. They both really lean on Location of Behavior over Separation of concerns. They do really well at making small components that you can throw on and endpoint and stack into any page. With tailwind I just configure it to look at all my templates, and I can guarantee that the styles will be in app.css, and all I need to do is add classes to my component.

Heres a sample component for a user widget that will go on every page. It has everything it needs right in the template.

<div
  hx-swap-oob="outerHTML"
  id="user-header"
  class="absolute top-0 right-0 mt-8 mr-4"
>

<!--markata-attribution-->
  {% if current_user %}

<!--markata-attribution-->
  <details

<!--markata-attribution-->
    id="user-header-details"

<!--markata-attribution-->
    open
    class="group list-none px-4 py-2 self-center justify-self-center bg-neutral-600/10 shadow-lg shadow-zinc-950/20 ring-2 ring-zinc-950/5 rounded-xl flex justify-center align-center flex-col"
  >
    <summary style="list-style-type: none">{{ current_user.username }}</summary>

<!--markata-attribution-->
    <div class="hidden group-hover:block my-4">

<!--markata-attribution-->
      <a
        class="mt-6 px-4 py-2 rounded bg-purple-950/5 ring-2 ring-cyan-500/30 text-cyan-500 font-bold"

<!--markata-attribution-->
        href="{{ url_for('get_logout') }}"
      >

<!--markata-attribution-->
        Logout
      </a>

<!--markata-attribution-->
    </div>

<!--markata-attribution-->
  </details>

  {% else %}
  <a
    href="{{ url_for('post_login') }}"
    class="mt-5 text-xl text-white font-bold text-shadow-xl text-shadow-zinc-950"
  >

<!--markata-attribution-->
    login
  </a>

<!--markata-attribution-->
  {% endif %}

<!--markata-attribution-->
</div>

internal apps #

I’ve built several interal apps, and tailwind has been really great for this. Its super quick to pop classes on components and get things to look decent quickly, or put some real polish into making them look nice.

My Website waylonwalker.com #

I’ve dropped my old decrepid css for some tailwind on my main site. My css was much smaller, but did not work quite as well on all devices, and most importantly was becoming a house of cards. Every time I fixed one thing several other things would fail. Colors were a bit muddy, and not as nicely configured as tailwind.

Most importantly was becoming a house of cards. Every time I fixed one thing several other things would fail.

One rough side of styling a blog in tailwind is that you don’t necessarily have control over granular details of how your pages get rendered without getting really deep into the markdown renderer, or writing your posts in html. It ends up looking a bit ugly, and is against the tailwind best practices, but it seems like the best way for a site like this.

@tailwind base;
@tailwind components;
@tailwind utilities;
@import "./highlight.css";

.social {
  @apply font-bold;
  @apply flex flex-row;
  @apply gap-4;
  @apply justify-center;
  @apply py-8;
}

#posts ul ul {
  @apply backdrop-blur-sm;
  @apply flex flex-col sm:grid grid-flow-row-dense;
  @apply gap-4;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  @apply p-4;
}

grid #

I’ve struggled to use grid on my projects, and I’ve tried a few different times with no real success or adoption, but started using it on my resume, to have a main middle column, with two outer full bleed columns where I can make some elements full bleed to the edge. tailwind made this easy, once done, I had an admonition that was beautiful full bleed with a touch of color.

page-break-after CSS property - CSS | MDN The page-break-after CSS property adjusts page breaks after the current element. MDN Web Docs · developer.mozilla.org [1] I’m working on something that might go to print, so I want the page breaks to happen somewhat in my control as the content author. As I do my writing I break my content up in to many short sections using h2, sometimes an h3. These are generally short sections that go together, should stay together, and typically are not too lengthy to cause a large white space in print. I found a way in css to only allow page breaks to happen on h2 and h3, and it turned out perfect, suck it WSIWIG editors * { page-break-before: avoid; } h2, h3 { page-break-before: auto; } References: [1]: https://developer.mozilla.org/en-US/docs/Web/CSS/page-break-after
How to Build a Website or App - Syntax #696 This podcast episode covers a wide range of topics related to building a website or web application from start to finish. syntax.fm [1] Great tips in this one. They discuss everything from front end to backend, databases and ORMS, here are a few of my favorite points. - Use good data or good fake data - make it have some variation like long and short text - Don’t use a database if you need one, static content is eaiser to manage - end to end test, (does the site load page x) - You DONT NEED all this complexity, you can deploy a site with HTML [2] and CSS. References: [1]: https://syntax.fm/show/696/how-to-build-a-website-or-app [2]: /html/
Sebastián Ramírez (@tiangolo) on X Now @FastAPI has 65k+ GitHub stars! ✨🎉 Since today, FastAPI has a few more GitHub stars than Flask. 🤯 Now FastAPI is the second most starred Python web framework, right after Django. 🥈 X (formerly Twitter) · twitter.com [1] Fastapi [2] passes flask in GitHub stars! [1] References: [1]: https://twitter.com/tiangolo/status/1729153717956715007 [2]: /fastapi/
- Nice take by @t3dotgg [1]. Some of the old patterns that go deep into webdev, MVC, separation of concerns, REST, are things we are told to believe on day one, thrown so many things, no mental bandwidth, or experience to form our own opinions we must take them as fact. Rarely do we take these facts and revisit them with our new understandings years later. References: [1]: https://twitter.com/t3dotgg
Heroicons Beautiful hand-crafted SVG icons, by the makers of Tailwind CSS. Heroicons · heroicons.com [1] heroicons is a really nice set of many of the basic icons that you will need for building nice ui’s. They have a really nice copy as svg or jsx button, so that you can just yank it and paste it on your page without any extra packages or installation. References: [1]: https://heroicons.com/
Wes Bos (@wesbos) on X 🔥 The stale-while-revalidate header is suuuuuuper handy for striking a balance between fast loads and and frequently changed content. Here I am using it to instantly deliver an OG image that t… X (formerly Twitter) · twitter.com [1] Wes has some of the coolest OG [2] images i’ve ever seen. Here he talks about how to enable cache configuration so that its constantly updating the cache without the user waiting for the image to be created. References: [1]: https://twitter.com/wesbos/status/1717923624559005977 [2]: /og/
htmx ~ Locality of Behaviour (LoB) Carson Gross explores the Locality of Behaviour (LoB) principle, which emphasizes making the behavior of code units obvious on inspection to enhance maintainability. He discusses the tradeoffs betw... htmx.org [1] Interesting principle here. What a great example, If I’m looking at the second jQuery example, I have to dig into dev tools or make some assumtions that this team uses jQuery, and selects by id, therefore I can grep for $("#d1"). Consider two different implementations of an AJAX request in HTML [2], the first in htmx [3]: <!--markata-attribution--> <button hx-get="/clicked">Click Me</button> > and the second in jQuery: ``` js $("#d1").on("click", function(){ $.ajax({ /* AJAX options... */ }); }); <button id="d1">Click Me</button> References: [1]: https://htmx.org/essays/locality-of-behaviour/ [2]: /html/ [3]: /htmx/