Skip to content

Instantly share code, notes, and snippets.

View thenetaji's full-sized avatar
🎯
Vibing

thenetaji thenetaji

🎯
Vibing
View GitHub Profile
@thenetaji
thenetaji / gist:538d5669ac3bc0498fba04813e8e2378
Last active December 22, 2025 08:03
A robust utility function to reliably extract the 11-character YouTube video ID from all official URL formats

A robust utility function to reliably extract the 11-character YouTube video ID from all official URL formats. Most solutions break on edge cases, but this logic handles variations including shorts, live streams, and mobile URLs.

Supported URL Formats

The extractor supports the following formats, including those with extra parameters (like ?t= or &si=):

  • Standard: youtube.com/watch?v=VIDEO_ID
  • Shortened: youtu.be/VIDEO_ID
  • Shorts: youtube.com/shorts/VIDEO_ID
  • Embeds: youtube.com/embed/VIDEO_ID
@thenetaji
thenetaji / index.js
Last active December 12, 2025 07:41
Using cloudflare d1 outside workers
import Cloudflare from "cloudflare";
import "dotenv/config";
const api_token = process.env.CLOUDFLARE_D1_ACCESS_TOKEN;
const account_id = process.env.CLOUDFLARE_ACCOUNT_ID;
const database_id = process.env.CLOUDFLARE_DB_ID;
const client = new Cloudflare({ apiToken: api_token });
async function runQuery(sql, params = []) {