Public code snippets shared by developers. Search, copy, or share your own.
import asyncio
import httpx
async func fetch_url(url: str) -> dict:
async with httpx.AsyncClient() as client:
response = await client.get(url)
return response.json()
# Utilisation : data = asyncio.run(fetch_url("https://api.example.com/data"))package main
import (
"encoding/json"
"net/http"
)
func main() {
http.HandleFunc("/api/health", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{"status": "ok"})
})
http.ListenAndServe(":8080", nil)
}function debounce(fn, delay = 300) {
let timeoutId;
return (...args) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => fn(...args), delay);
};
}async function fetchData(url) {
try {
const response = await fetch(url);
if (!response.ok) throw new Error(`Erreur HTTP: ${response.status}`);
return await response.json();
} catch (error) {
console.error("Échec de la requête :", error.message);
}
}A minimal debounce helper — click into it to see the full snippet page.
function debounce<T extends (...args: unknown[]) => void>(fn: T, delayMs: number) {
let timer: ReturnType<typeof setTimeout>;
return (...args: Parameters<T>) => {
clearTimeout(timer);
timer = setTimeout(() => fn(...args), delayMs);
};
}