Snippet Python
11 snippet
-
2026-07-04 · Menengah · Otomasi
Celery priority queue dengan Redis backend
Celery worker dengan priority queue — urgent task (notification user) jalan duluan dari batch email. Pakai Redis broker dengan queue per priority.
-
2026-06-29 · Menengah · Performance
Custom Prometheus counter + histogram di Python
Instrument FastAPI / Flask dengan Prometheus counter + histogram. Track business metric (order, payment) bukan cuma RED metric.
-
2026-06-21 · Lanjut · Performance
Distributed lock pattern Redis (Redlock)
Distributed lock dengan Redis — pastikan job hanya jalan di satu worker sekaligus. SET NX EX pattern + token validation untuk safety.
-
2026-06-20 · Menengah · Performance
FastAPI rate limit dengan Redis token bucket
Rate limit FastAPI pakai Redis token bucket — atomic, distributed-friendly, support burst. Lebih akurat dari sliding counter.
-
2026-06-17 · Menengah · AI
Anthropic Batch API: 50% diskon untuk async
Batch API Anthropic kasih diskon 50% buat job yang gak butuh real-time. Cocok untuk content moderation harian, summarization bulk, classification.
-
2026-06-05 · Lanjut · AI
RAG sederhana: Claude + pgvector + chunks
Pipeline RAG end-to-end: chunk dokumen kebijakan BPJS, embed, retrieve top-K, generate jawaban Claude. Tanpa LangChain.
-
2026-06-04 · Menengah · AI
Store embedding ke pgvector Postgres
Simpan embedding produk Tokopedia ke Postgres pgvector + query similar dengan cosine distance. Tanpa vector DB komersial.
-
2026-05-28 · Pemula · Parsing
Parse string rupiah ke integer di Python
Konversi 'Rp 1.500.000,00' atau 'Rp1.5jt' menjadi integer 1500000. Handle pemisah ribuan titik, koma desimal, dan singkatan jt/rb.
-
2026-05-26 · Pemula · Utility
Tee output ke file + stdout simultan (Python)
Print ke terminal sekaligus log ke file. Tidak perlu redirect manual. Wrap stdout dengan custom class. 10 lines.
-
2026-05-24 · Menengah · Otomasi
Parallel HTTP request dengan asyncio + httpx + Semaphore
Hit 100 URL paralel dengan rate limit. Async semaphore untuk control concurrency. Lebih cepat 10x dari sequential, lebih sopan dari unbounded parallel.
-
2026-05-22 · Menengah · Scraping
Scrape harga produk + parse rupiah dengan httpx
Async scraping daftar URL produk, extract harga dengan selector CSS, lalu parse ke integer rupiah. Rate-limited supaya tidak diblokir.