I am working on a page for
htmx-patterns and I ran into a
situation with lots of duplication. Especially when i am using tailwind I run
into situations where the duplication can get tedious to maintiain. The
solution I found is macros.
Now I can use the same code for all of my links, and call the macro to use it.
jinja has a loop variable that is very handy to use with htmx. Whether you
want to implement a click to load more or an infinite scroll this loop variable
is very handy.
{% for person in persons %}
<li{%ifloop.last%}hx-get="{{ url_for('infinite', page=next_page) }}"hx-trigger="intersect once"hx-target="#persons"hx-swap='beforeend'hx-indicator="#persons-loading"{%endif%}{{person.name.upper()}}-{{person.phone_number}}</li>{% endfor %}
Now for every chunk of contacts that we load we will trigger the infinite
scroll by loading more once the last one has intersected the screen.
Writing
Out of the box Starlette does not support url_for with query params. When
trying to use url_for with query params it throws the following error.
In my searching for this I found starlette issue #560 quite helpful, but not complete, as it did not work for me.
importjinja2ifhasattr(jinja2,"pass_context"):pass_context=jinja2.pass_contextelse:pass_context=jinja2.contextfunction@pass_contextdefurl_for_query(context:dict,name:str,**params:dict)->str:request=context["request"]url=str(request.url_for(name))ifparams=={}:returnurlfromurllib.parseimportparse_qs,urlencode,urlparse,urlunparse# Parse the URLparsed_url=urlparse(url)# Parse the query parametersquery_params=parse_qs(parsed_url.query)# Update the query parameters with the new onesquery_params.update(params)# Rebuild the query stringupdated_query_string=urlencode(query_params,doseq=True)# Rebuild the URL with the updated query stringupdated_url=urlunparse((parsed_url.scheme,parsed_url.netloc,parsed_url.path,parsed_url.params,updated_query_string,parsed_url.fragment,))ifos.environ.get("ENV")in["dev","qa","prod"]:updated_url=updated_url.replace("http","https",1)returnupdated_urldefget_templates():templates=Jinja2Templates(directory="templates")templates.env.globals["url_for"]=url_for_queryreturntemplates
https
If you want url_for to work in production you need some way to convert http
to https. Here is how I make it work, for local development I export ENV=local then for each environment that I am running on a server I include
it in the list and update ENV appropriately.
To access the home route using url_for in a jinja template you can use the
following, once you have applied the url_for_query function as your default
url_for
<ahref="{{ url_for('home', page=1) }}">Home</a>
Writing
Kind (Kubernetes in Docker) is a tool that makes it easy to create and tear
down local clusters quickly. I like to use it to test out new workflows.
Argocd is a continuous delivery tool that makes it easy to setup gitops
workflows in kubernetes.
Here is how you can setup a new kind cluster and install argocd into it using
helm, the kubernetes package manager.
kind create cluster --name argocd
# your first time through you need to add the argocd repohelm repo add argo https://argoproj.github.io/argo-helm
helm repo update
# install argocd into the clusterhelm install argo argo/argo-cd --namespace argocd --create-namespace
# deploy the app of appskubectl apply -f apps/apps.yaml
If you want to add repos and apps to your cluster you can use the argo cli to
do that, but first you will need forward the argocd port and login.
# Wait until Argo CD API server is availableecho"Waiting for Argo CD API server to be available..."while ! kubectl wait --for=condition=available --timeout=60s deployment/argo-argocd-server -n argocd;doecho"Waiting for Argo CD API server to be ready..." sleep 10donekubectl port-forward svc/argo-argocd-server -n argocd 8080:443 &argocd_admin_password=$(kubectl get secret argocd-initial-admin-secret -n argocd -o jsonpath="{.data.password}"| base64 -d)argocd login localhost:8080 --insecure --username admin --password $argocd_admin_passwordargocd repo add https://github.com/fokais-com/app.fokais.git --username waylonwalker --password ${GH_ARGO_PAT}argocd app create app-fokais-local --repo https://github.com/fokais-com/app.fokais.git --path k8s/overlays/local --dest-server https://kubernetes.default.svc --sync-policy automated --sync-option Prune=true
I have several feeds that you can consume my content with. Many posts will cross between them, so if you would like to follow a certain stream of content in your rss reader thats what this is for. This one might feel like it has some extra noise with multiple posts per day, including starts, and instagram style posts,…
These are generally my thoughts on a web page or some sort of url, except a rare few don’t have a link. These are dual published off of my thoughts.waylonwalker.com site. It’s a fully dynamically rendered site 2000’s style. Posts are stored in a database and instantly available. Almost all of the posts were written in…
I’m really excited about fastapi-observability, an amazing project by blueswen. It’s worth exploring! Observe FastAPI app with three pillars of observability: Traces (Tempo), Metrics (Prometheus), Logs (Loki) on Grafana through OpenTelemetry and OpenMetrics.
If you’re into interesting projects, don’t miss out on taipy, created by Avaiga. Turns Data and AI algorithms into production-ready web applications in no time.
External Link dotesports.com Damn this button had me stuck for way too long. It definitely looks like a button once I see it, but I don’t recall coming into contact with many buttons in the game, I tried to set it ablaze, pull it, fly it, nothing.
External Link help.socialbee.com YouTube makes finding rss feeds way too hard. Hats off to them for still supporting it, allowing you to find content outside the algorithm, and consuming content you asked for. But i had no idea you had to search the source code to get it.
Optimizing SQLite for servers SQLite is often misconceived as a "toy database", only good for mobile applications and embedded systems because it's default configuration is optimized for embedded use cases, so most... Sylvain Kerkour · kerkour.com Very interesting article by Sylvain, suggested by Simon Will…
Inspiring story transitioning into tech from nursing. I also came to tech through a set of circumstances that made it difficult for me to excel at my current job. Looking back it is something that I was always interested in and I was just unsure how to get in, I am so glad that I figured it out, it has been such a grea…
Mar 25 – Mar 31, 20242 years ago
Featured this week / Writing
In my homelab kubernetes cluster I am using kubeseal to encrypt secrets. I
have been using it successfully for a few months now wtih great success. It
allows me to commit all of my secrets manifests to git with out risk of leaking
secrets.
You see kubeseal encrypts your secrets with a private key only stored in your
cluster, so only the cluster itself can decrypt them using the kubeseal
controller.
Most of these commands come straight from the docs. From my experience I have
always specified the namespace, my projects go per namespace and I don’t have
any reason that other namepsaces should see the secret, and if they do I deploy
another secret in that namespace.
# Create a json/yaml-encoded Secret somehow:# (note use of `--dry-run` - this is just a local file!)echo -n bar | kubectl create secret generic mysecret --dry-run=client --from-file=foo=/dev/stdin -o yaml -n thenamespace > mysecret.yaml
note that the key of the secret is foo and the value is bar
# This is the important bit:kubeseal -f mysecret.yaml -w mysealedsecret.yaml
# At this point mysealedsecret.json is safe to upload to Github,# post on Twitter, etc.# Eventually:kubectl create -f mysealedsecret.yaml -n thenamespace
# sealedsecret.bitnami.com/mysecret created# Profit!kubectl get secret mysecret
kubectl get secret mysecret -n thenamespace
# NAME TYPE DATA AGE# mysecret Opaque 1 27scat mysealedsecret.yaml | kubeseal --validate
Now the main downside I see with kubeseal is that it does not provide a way to
store your secrets in a way that you can access outside of your cluster. So
you need to make sure that you have another solution in place to store your
secrets so that you still have them if you ever were to take the cluster down
or move from k8s to something else.
Overall the likelyhood of you loosing a production cluster is pretty low, so
maybe it’s ok to just trust it depending on what the secrets are. Especially
for things you control and can rotate anyways its fine.
I stumbled into kubernetes December 2023 when I was looking for a better way to self host applications. I was looking for something that didn’t require logging into a server and building and deploying like a cave man. I wanted a smoother experience than docker compose was giving me. https://waylonwalker.com/looking-for…
Some Git poll results Some Git poll results Julia Evans · jvns.ca great poll of git questions poll: did you know that in a git merge conflict, the order of the code is different when you do a merge/rebase? merge: <<<<<<< HEAD YOUR CODE OTHER BRANCH’S CODE c694cf8aabe rebase: «««< HEAD OTHER BRANCH’S CODE YOUR CODE d945…
External Link sealed-secrets.netlify.app kubeseal is a pretty simple to get started with way to manage secrets such that they can be stored in a git repo and be picked up by your continuous delivery service. Sealed Secrets provides declarative Kubernetes Secret Management in a secure way. Since the Sealed Secrets are e…
Great episode covering a seemingly simple topic. What I really benefitted from was hearing all the different use cases, from logging, debugging, to a/b testing, caching, and auth. I hadn’t even thought of it being applied to a router. I thought of it being applied for an entire application. This seems very useful for t…
![[None]] I’ve been using these decorators to modify the behavior of specific routes. It will do things like 404 admin only routes in a way that looks just like fastapi ’s default, or only allow certain roles into the route, or redirect unauthenticated users to login. After listening to yesterday’s syntaxfm I’m now rea…
Simon Willison (@simonw) on X TIL Google Chrome has a --headless option you can use to take a screenshot from the CLI that's built into the default installation X (formerly Twitter) · twitter.com Huh, so this is just built right into the chrome cli.
strawberry-sqlalchemy by strawberry-graphql is a game-changer in its space. Excited to see how it evolves. A SQLAlchemy Integration for strawberry-graphql
I recently discovered AnyText by tyxsspa, and it’s truly impressive. Official implementation code of the paper <AnyText: Multilingual Visual Text Generation And Editing>
![[None]] jinja’s in fastapi does not account for https by default, there is probably a better way, but this is a way that allows me to configure when I use http vs https.
@cassidoo) on X — I MADE AN APP ✨" loading="lazy"> Cassidy ( @cassidoo) on X I MADE AN APP ✨ X (formerly Twitter) · twitter.com Damn are one time paid and have it apps making a comeback? Seems like the perfect thing to have someone else automate and not pay a subscription for. Genius Idea Cassidy!! Now what do you call…
Joining the split keyboards club: a Moonlander story | Carlos Becker This post will describe my experience with a couple of firsts: carlosbecker.com I switched from a 60% vortex pok3r to a 40% corne June, 2021. I can relate to a lot of what Carlos talks about here. I think going from 60%-40% made my journey harder than…
My workflow, part 1 | Carlos Becker I keep getting asked how my setup works, how I use tmux and nvim over ssh… all that good stuff. carlosbecker.com Carlos has a pretty sick setup here, I can relate to mostly, cept the macos part. My main critique is that I don’t think he gave window managers much chance on linux, and…
Using Netlify Analytics to Build a List of Popular Posts The other day, the wind blew and I decided to realign the design of my blog just a bit. One of the things I wanted to change was the content on my home page… blog.jim-nielsen.com This is a sick feature of Jim’s blog, I am really inspired by this. I am not sure ho…
I’m really excited about full-stack-fastapi-template, an amazing project by fastapi. It’s worth exploring! Full stack, modern web application template. Using FastAPI, React, SQLModel, PostgreSQL, Docker, GitHub Actions, automatic HTTPS and more.
605: Jim Nielsen on Subversive URLs, Blogging + AI, and Design Engineers Jim Nielsen joins us to about URLs and linking as the new subversive way to maintain the web, paying for news in Canada, should content creators be worried about AI, the case for design engineers, … ShopTalk · shoptalkshow.com An absolute fantasti…
Configure Liveness, Readiness and Startup Probes This page shows how to configure liveness, readiness and startup probes for containers. For more information about probes, see Liveness, Readiness and Startup Probes. Before you beginYou need to ha... Kubernetes · kubernetes.io What is the difference between health, live…
External Link stackoverflow.com The convention of “z-pages” comes from google and reduces the likelihood of collisions with application endpoints and keep the convention across all applications.
Placehold Placehold is a simple, fast and free image placeholder service to generate SVG, PNG, JPEG, GIF, WebP and AVIF placeholder images for your project. placehold.co This is a handy placeholder generator for generating placeholder items like images, and videos.
If you’re into interesting projects, don’t miss out on datasette-litestream, created by datasette. Datasette plugin for streaming SQLite database backups to S3, using Litestream!
I came across minio from minio, and it’s packed with great features and ideas. MinIO is a high-performance, S3 compatible object store, open sourced under GNU AGPLv3 license.
![[None]] I figured out the killer combination for python lsp servers, ruff and jedi! ruff does all of the diagnostics and formatting, then jedi handles all the code objects like go to definition and go to reference.
Client Challenge pypi.org Underrated python library to on board ruff, or just use it on a project where its not the norm. ruff claims that its 99.9% compatible with black and when you read through the known differences they are clearly edge case bugs in black. See this page for more about the comparison to black https:…
![[None]] First I need to fetch my thoughts from the api, and put it in a local sqlite database using. Now that I have my posts in a local sqlite database I can use to enable full text search and populate the full text search on the post table using the title message and tags columns as search. Now I am ready to search…
External Link screenshots.waylonwalker.com This is the best tree I have ever built in minecraft. It took at least 4 stacks of logs and leaves despite what it looks like. It is placed where Welscraft’s island in the hermitcraft season 10 seed, but on our own server we call lonecraft. We started this server a few weeks a…
Formatting codes – Minecraft Wiki Formatting codes (also known as color codes) add color and modifications to text in-game. Minecraft Wiki · minecraft.wiki Minecraft MOTD and server names have formatting codes so that you can get colors, bold, underlined, italics, in your message of the day or server name. See the arti…
GitHub - jesseduffield/lazydocker: The lazier way to manage everything docker The lazier way to manage everything docker. Contribute to jesseduffield/lazydocker development by creating an account on GitHub. GitHub · github.com I’ve been using this for a few weeks now and it’s fantastic. It’s reminds me of lazygit, it g…
Go is feeling more and more like something I could throw in my tool belt as a python dev. I really like that it’s garbage collected and has great error management. I am just not sure how to work it in without it being the main thing. The thing that is so cool is the ability to ship tiny pre-compiled binaries that just…
Great example from Anthony showing how easy it is to practice building database orm models and playing with them in a repl. This is good practice even if you are in a big code base to be able to test and learn in a simplified code base that does not have a mountain of other code around atuh, permissions, security, and…
External Link stackoverflow.com Today I came across some sqlalchemy models that created some relationships, some used some used. I was stumped why, I had never came accross before and I felt skill issues sinking in. backref is considered legacy https://docs.sqlalchemy.org/en/14/orm/backref.html As stated in the sqlalch…