Code Snippets & Syntax Highlighting
Platform content supports inline code and fenced code blocks using standard GFM
syntax. Language tags enable syntax highlighting in the browser.
Inline code
Dalam Python, luminositas dihitung dengan L = 4 * pi * R**2 * sigma * T**4.
Satuan SI untuk tetapan Stefan–Boltzmann adalah 5.67e-8 W m⁻² K⁻⁴.
Akses elemen terakhir array NumPy: arr[-1], atau setiap elemen ganjil: arr[::2].
Python — simulasi orbit Kepler
import numpy as np
# Orbital parameters (Earth around Sun)
G = 6.674e-11 # N m² kg⁻²
M = 1.989e30 # kg (solar mass)
a = 1.496e11 # m (semi-major axis, 1 AU)
e = 0.0167 # orbital eccentricity
# True anomaly array (full orbit)
nu = np.linspace(0, 2 * np.pi, 1_000)
# Polar form: r = a(1 − e²) / (1 + e cos ν)
r = a * (1 - e**2) / (1 + e * np.cos(nu))
# Vis-viva: v² = GM(2/r − 1/a)
v = np.sqrt(G * M * (2 / r - 1 / a))
print(f"Perihelion: {r.min()/1.496e11:.4f} AU, v = {v.max()/1e3:.2f} km/s")
print(f"Aphelion: {r.max()/1.496e11:.4f} AU, v = {v.min()/1e3:.2f} km/s")
TypeScript — KaTeX rendering helper
import katex from 'katex';
export function renderMath(tex: string, displayMode = false): string {
return katex.renderToString(tex, {
displayMode,
throwOnError: false,
trust: false,
strict: false,
macros: {
'\\RR': '\\mathbb{R}',
'\\NN': '\\mathbb{N}',
},
});
}
// Usage
const block: string = renderMath(String.raw`E = mc^2`, true);
const inline: string = renderMath(String.raw`\gamma = \frac{1}{\sqrt{1 - v^2/c^2}}`);
document.getElementById('display')!.innerHTML = block;
document.getElementById('inline')!.innerHTML = inline;
SQL — quiz leaderboard query
SELECT
u.name,
COUNT(qa.id) AS attempts,
MAX(qa.score) AS best_score,
ROUND(AVG(qa.score)::numeric, 2) AS avg_score,
MIN(qa.completed_at) AS first_attempt
FROM quiz_attempts qa
JOIN users u ON u.id = qa.user_id
WHERE qa.quiz_id = $1
AND qa.completed_at IS NOT NULL
GROUP BY u.id, u.name
ORDER BY best_score DESC, avg_score DESC
LIMIT 20;
LaTeX source → live rendered output
The fenced source block below is rendered immediately after it:
\begin{align}
i\hbar\frac{\partial \Psi}{\partial t}
&= -\frac{\hbar^2}{2m}\nabla^2\Psi + V(\mathbf{r})\Psi \\
\hat{H}\,|\Psi\rangle
&= E\,|\Psi\rangle
\end{align}
\begin{align}
i\hbar\frac{\partial \Psi}{\partial t}
&= -\frac{\hbar^2}{2m}\nabla^2\Psi + V(\mathbf{r})\Psi \\
\hat{H}\,|\Psi\rangle
&= E\,|\Psi\rangle
\end{align}
Bash — build and deploy script
#!/usr/bin/env bash
set -euo pipefail
# Build the Astro site
npm run build
# Sync static assets with long-lived immutable cache headers
aws s3 sync ./dist "s3://${BUCKET}" \
--cache-control "max-age=31536000,immutable" \
--exclude "*.html"
# HTML gets no-cache so routing always reflects the latest deploy
aws s3 sync ./dist "s3://${BUCKET}" \
--cache-control "no-cache" \
--include "*.html"
# Invalidate CloudFront edge caches
aws cloudfront create-invalidation \
--distribution-id "${CF_DIST_ID}" \
--paths "/*"
echo "✓ Deploy complete."
JSON — quiz API response shape
{
"quiz": {
"id": 42,
"title": "Hukum Kepler & Mekanika Orbit",
"questionCount": 20,
"timeLimit": 3600,
"settings": {
"attemptLimit": 3,
"examMode": "hard-window",
"availableFrom": "2026-07-10T00:00:00.000Z",
"availableUntil": "2026-07-17T23:59:59.000Z"
}
},
"attempt": {
"number": 1,
"startedAt": "2026-07-02T08:00:00.000Z",
"timerEndAt": "2026-07-02T09:00:00.000Z",
"submissionKey": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}
}
Demo: Mathpix-Style Rendering