flask
bookmark_border
Make email-verification or reset links that expire, without a database table.
from itsdangerous import URLSafeTimedSerializer, BadSignature, SignatureExpired
serializer = URLSafeTimedSerializer(app.config["SECRET_KEY"], salt="email-verify")
intermediate
#auth #email #tokens
python
bookmark_border
Turn any title into a lowercase, URL-safe slug.
import re
import unicodedata
def slugify(text: str) -> str:
beginner
#strings #regex #urls
html
bookmark_border
The tags that control how a link looks on social apps and chat.
<head>
<title>Bakery pre-orders — Ada Studio</title>
<meta name="description" content="Order bread online and pick it up warm.">
<meta property="og:type" content="website">
<meta property="og:title" content="Bakery pre-orders">
beginner
#seo #meta #sharing
css
bookmark_border
Keep the footer at the bottom of the window on short pages.
body {
margin: 0;
min-height: 100dvh;
display: flex;
flex-direction: column;
beginner
#layout #flexbox #footer
python
bookmark_border
A tiny context manager that prints how long a block took.
import time
from contextlib import contextmanager
@contextmanager
intermediate
#performance #context-manager
sql
bookmark_border
The 3 best-selling products in every category with ROW_NUMBER().
SELECT category, product, revenue
FROM (
SELECT c.name AS category,
p.name AS product,
SUM(oi.quantity * oi.unit_price) AS revenue,
advanced
#window-functions #ranking #reports
css
bookmark_border
Show an ellipsis after three lines.
.excerpt {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
line-clamp: 3;
beginner
#typography #text
python
bookmark_border
Use __post_init__ to reject bad values as soon as an object is created.
from dataclasses import dataclass, field
@dataclass
class Product:
intermediate
#dataclasses #validation #types
css
bookmark_border
Show a clear focus ring for keyboard users without showing it on mouse clicks.
:where(a, button, input, select, textarea):focus { outline: none; }
:where(a, button, input, select, textarea):focus-visible {
outline: 3px solid #2f6bff;
outline-offset: 2px;
border-radius: 6px;
beginner
#accessibility #focus
bash
bookmark_border
Retry until a TCP port answers, with a timeout.
wait_for() {
local host="$1" port="$2" timeout="${3:-30}"
for ((i = 0; i < timeout; i++)); do
if (exec 3<>"/dev/tcp/$host/$port") 2>/dev/null; then
echo "$host:$port is up"; return 0
intermediate
#docker #deploy #networking