Skip to content

Instantly share code, notes, and snippets.

@theSoberSobber
Last active January 12, 2026 16:38
Show Gist options
  • Select an option

  • Save theSoberSobber/c1d89f41162f743ca35992270a192b52 to your computer and use it in GitHub Desktop.

Select an option

Save theSoberSobber/c1d89f41162f743ca35992270a192b52 to your computer and use it in GitHub Desktop.
Filtering CLIST API over a serverless function.
// URLS:
// Codeforces: https://filtered-cal.vercel.app/api/codeforces
// Codechef: https://filtered-cal.vercel.app/api/codechef
// Atcoder: https://filtered-cal.vercel.app/api/atcoder
const express = require("express");
const app = express();
/**
* Keyword filters (lowercase)
*/
const FILTERS = {
codeforces: ["icpc"],
codechef: ["dsa challenge"],
atcoder: ["heuristic"]
};
/**
* Source calendars
*/
const SOURCES = {
codeforces:
"https://calendar.google.com/calendar/ical/br1o1n70iqgrrbc875vcehacjg@group.calendar.google.com/public/basic.ics",
codechef:
"https://calendar.google.com/calendar/ical/ogc7qt4hlg454ggkj9o6ttqnq8@group.calendar.google.com/public/basic.ics",
atcoder:
"https://calendar.google.com/calendar/ical/vdobhfoodrv59522b684lhfs7c@group.calendar.google.com/public/basic.ics"
};
app.get("/api/:platform", async (req, res) => {
const { platform } = req.params;
const url = SOURCES[platform];
const filters = FILTERS[platform];
if (!url || !filters) {
return res.status(404).send("unknown platform");
}
const upstream = await fetch(url);
// forward important headers
[
"content-type",
"cache-control",
"pragma",
"expires"
].forEach(h => {
const v = upstream.headers.get(h);
if (v) res.setHeader(h, v);
});
const text = await upstream.text();
const lines = text.split(/\r?\n/);
let out = [];
let buf = [];
let inEvent = false;
let drop = false;
for (const line of lines) {
if (line === "BEGIN:VEVENT") {
inEvent = true;
drop = false;
buf = [line];
continue;
}
if (line === "END:VEVENT") {
buf.push(line);
if (!drop) out.push(...buf);
inEvent = false;
continue;
}
if (inEvent) {
buf.push(line);
const lower = line.toLowerCase();
if (filters.some(w => lower.includes(w))) {
drop = true;
}
} else {
out.push(line);
}
}
res.send(out.join("\r\n"));
});
app.listen(3000, () => {
console.log("ICS filter running on :3000");
});
{
"name": "filtered-cal",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "commonjs",
"dependencies": {
"express": "^5.2.1"
}
}
{
"builds": [
{
"src": "index.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "index.js"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment