GitHub Actions – Matrix Strategy

#devops
#githubactions

Use matrix to run multiple OS or versions in parallel:

  strategy:
    matrix:
      os: [ubuntu-latest, windows-latest]
      node: [14, 16]

Official Docs

FastAPI: ZSH: Show current Git branch in prompt

#devops
#terminal

Add this to your .zshrc to show Git branch:

autoload -Uz vcs_info
precmd() { vcs_info }
PS1='%~ %{$fg[green]%}${vcs_info_msg_0_}%{$reset_color%} %# '

Official Docs

FastAPI: Tailwind: Arbitrary Values

#frontend
#tailwindcss

You can pass custom values using square brackets:

<div class="w-[37px] h-[55px]">Custom Size</div>

Official Docs

FastAPI: Dependency Injection

#backend
#fastapi

Define reusable dependencies using Depends:

from fastapi import Depends

def get_db(): yield SessionLocal()

@app.get("/users/")
def read_users(db: Session = Depends(get_db)):
...

Official Docs

Docker Healthcheck

#devops
#docker

Add a healthcheck to your Dockerfile:

HEALTHCHECK CMD curl --fail http://localhost:8000/health || exit 1

React: Key Prop Warning

#frontend
#react
#css

Always use a unique key when mapping lists. Avoid using array index if the order might change.

Django ORM: Q objects

#backend
#django

For complex queries, use Q objects:

from django.db.models import Q
User.objects.filter(Q(name__icontains="Arshad") | Q(role="admin"))

Kubernetes: Exec into Pod

#devops
#kubernetes

Quick command to debug a pod:

kubectl exec -it <pod-name> -- /bin/bash

CSS clamp() for Responsive Fonts

#frontend
#css

Use clamp() for fluid sizing:

  font-size: clamp(1rem, 2vw, 2rem);

dependsOn dengan ^ menandakan task dari package lain, sedangkan yang tanpa ^ task dari package itu sendiri.

Misal: app A pas mau build harus running tasks lint di semua package dependenciesnya, dan juga harus running task test app A itu sendiri.

SQL: Filter NULL vs empty string

#backend
#SQL

NULL and '' are not the same:

SELECT * FROM users WHERE name IS NULL;
SELECT * FROM users WHERE name = '';