Hacker News API examples & templates
Use these vals as a playground to view and fork Hacker News API examples and templates on Val Town. Run any example below or find templates that can be used as a pre-built solution.
pomdtr
code_search_is_easy
HTTP
Code Search is Easy Earlier this week, Tom MacWright posted Code Search is Hard . He describes the research he his doing to improve the code search experience of Val Town . It was a great read, and you might have seen it trending on Hacker News . As Val Town's most active user (behind Steve Krouse, one of the founders of Val Town), I for sure agree with Tom that the search feature needs improvements. But while reading his post, I immediately thought of a different approach to the problem. And a few hours later, Val Town Search was born. Do things that don't scale How does this new shiny search engine work? Well, it's quite simple. I wrote a Deno script that fetches all vals from the Val Town API. #!/usr/bin/env -S deno run -A
import * as path from "https://deno.land/std/path/mod.ts";
const dir = path.join(import.meta.dirname!, "..", "vals");
const blocklist = Deno.readTextFileSync(
path.join(import.meta.dirname!, "blocklist.txt")
)
.split("\n")
.map((line) => line.trim())
.filter((line) => line.length > 0);
let url = `https://api.val.town/v1/search/vals?limit=100&query=+`;
const vals = [];
while (true) {
console.log("fetching", url);
const resp = await fetch(url);
if (!resp.ok) {
console.error(resp.statusText);
Deno.exit(1);
}
const { data, links } = await resp.json();
vals.push(...data);
if (!links.next) {
break;
}
url = links.next;
}
Deno.removeSync(dir, { recursive: true });
Deno.mkdirSync(dir, { recursive: true });
for (const val of vals) {
const slug = `${val.author.username}/${val.name}`;
if (blocklist.includes(slug)) {
console.log("skipping", slug);
continue;
}
const userDir = path.join(dir, val.author.username);
Deno.mkdirSync(userDir, { recursive: true });
Deno.writeTextFileSync(path.join(userDir, `${val.name}.tsx`), val.code);
} I pushed the data to a Github Repository (now private) I added a Github Action that runs the script every hour to refresh the data. #!/usr/bin/env -S deno run -A
import * as path from "https://deno.land/std/path/mod.ts";
const dir = path.join(import.meta.dirname!, "..", "vals");
const blocklist = Deno.readTextFileSync(
path.join(import.meta.dirname!, "blocklist.txt")
)
.split("\n")
.map((line) => line.trim())
.filter((line) => line.length > 0);
let url = `https://api.val.town/v1/search/vals?limit=100&query=+`;
const vals = [];
while (true) {
console.log("fetching", url);
const resp = await fetch(url);
if (!resp.ok) {
console.error(resp.statusText);
Deno.exit(1);
}
const { data, links } = await resp.json();
vals.push(...data);
if (!links.next) {
break;
}
url = links.next;
}
Deno.removeSync(dir, { recursive: true });
Deno.mkdirSync(dir, { recursive: true });
for (const val of vals) {
const slug = `${val.author.username}/${val.name}`;
if (blocklist.includes(slug)) {
console.log("skipping", slug);
continue;
}
const userDir = path.join(dir, val.author.username);
Deno.mkdirSync(userDir, { recursive: true });
Deno.writeTextFileSync(path.join(userDir, `${val.name}.tsx`), val.code);
} I created a simple frontend on top of the Github Search API that allows you to search the data. It's hosted on Val Town (obviously). That was it. I didn't have to build a complex search engine, I just used the tools that were available to me. Is this a scalable solution for Val Town? Probably not. Am I abusing the Github API? Maybe. Does it work better than the current search feature of Val Town? Absolutely! I hope that the val.town engineers will come up with a search feature that will put my little project to shame. But for now, you won't find a better way to search for vals than Val Town Search . PS: This post was written / is served from Val Town
1
maxm
hnhiringStats
Script
Scrapes hnhiring.com for the total count of job postings in every Who's Hiring post on Hacker News: 194 jobs, january 2025
337 jobs, december 2024
325 jobs, november 2024
342 jobs, october 2024
311 jobs, september 2024
328 jobs, august 2024
384 jobs, july 2024
351 jobs, june 2024
418 jobs, may 2024
306 jobs, april 2024
313 jobs, march 2024
356 jobs, february 2024
294 jobs, january 2024
337 jobs, december 2023
388 jobs, november 2023
353 jobs, october 2023
318 jobs, september 2023
367 jobs, august 2023
342 jobs, july 2023
358 jobs, june 2023
423 jobs, may 2023
380 jobs, april 2023
434 jobs, march 2023
465 jobs, february 2023
386 jobs, january 2023
505 jobs, december 2022
544 jobs, november 2022
481 jobs, october 2022
529 jobs, september 2022
664 jobs, august 2022
556 jobs, july 2022
753 jobs, june 2022
792 jobs, may 2022
771 jobs, april 2022
829 jobs, march 2022
841 jobs, february 2022
686 jobs, january 2022
788 jobs, december 2021
993 jobs, november 2021
816 jobs, october 2021
958 jobs, september 2021
882 jobs, august 2021
921 jobs, july 2021
1022 jobs, june 2021
888 jobs, may 2021
918 jobs, april 2021
945 jobs, march 2021
979 jobs, february 2021
0