← All one-liners·#001·discovery·self contained·beginner

Today's HN top 10, ranked by score

Pulls the top 30 HN story IDs, fetches each item in parallel, sorts by score, prints the top 10. Pure public API + jq + xargs.

The one-liner
$ curl -s "https://hacker-news.firebaseio.com/v0/topstories.json" \
  | jq -r '.[0:30][]' \
  | xargs -P 10 -I {} curl -s "https://hacker-news.firebaseio.com/v0/item/{}.json" \
  | jq -s -r 'sort_by(-.score) | .[0:10] | .[] | "[\(.score)] \(.title) — \(.url // "discussion")"'
What each stage does
  1. [01] curlcurl -s "https://hacker-news.firebaseio.com/v0/topstories.json"
    Fetch the array of the current top-500 story IDs from HN's Firebase API. -s = silent (no progress bar).
  2. [02] jqjq -r '.[0:30][]'
    Slice the first 30 IDs and emit one ID per line (raw, no quotes) so xargs can consume them.
  3. [03] xargsxargs -P 10 -I {} curl -s "https://hacker-news.firebaseio.com/v0/item/{}.json"
    For each ID, hit the item endpoint. -P 10 runs up to 10 fetches in parallel; -I {} substitutes the ID into the URL.
  4. [04] jqjq -s -r 'sort_by(-.score) | .[0:10] | .[] | "[\(.score)] \(.title) — \(.url // …
    -s slurps all 30 JSON items into one array. Sort by negative score (descending), take top 10, format each as a line with score, title, and URL (falling back to 'discussion' for Ask HN-style posts with no URL).
Expected output (sample)
[523] Show HN: We built a vector DB in 200 lines of Rust — https://example.com/vdb
[412] Apple Silicon M5 Pro benchmarks — https://example.com/m5
[388] The hidden cost of LLM batching — https://example.com/batching
... 7 more lines
Caveats & tips
  • Score is a snapshot — repeat to see ranking shift through the day.
  • xargs -P value: don't set higher than 20; HN rate-limits aggressive clients.