Skip to content

Instantly share code, notes, and snippets.

View wesbos's full-sized avatar
🔥
SLAYING BUGS

Wes Bos wesbos

🔥
SLAYING BUGS
View GitHub Profile
Delivered-To: wesbos@gmail.com
Received: by 2002:a05:7000:d13:b0:844:ae73:58c with SMTP id mt19csp142934mab;
Thu, 26 Mar 2026 07:30:27 -0700 (PDT)
X-Received: by 2002:a17:903:2f50:b0:2ae:593c:48fe with SMTP id d9443c01a7336-2b0b09e6752mr81510745ad.13.1774535427275;
Thu, 26 Mar 2026 07:30:27 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1774535427; cv=pass;
d=google.com; s=arc-20240605;
b=HBU7W/ibdMOp54XGM04Ej2KUuxJIlupSJZHxpFegVj3CX1ll6JrX1dUqEk0YWZLcs5
pIfMltp4F4WSd1TPCPSwveepGqqNXR5O1eJZzfURnL5LOH2I1RTaaYyk03G/jYGFjsUc
xTajrq0d52O5Mud4jMDAKB5UWojnHpBIHmirY9zvDL1/Me537me9bUclHgt26+VteevX
export class FPSMeter {
private frames: number[] = [];
private lastFrameTime: number = 0;
private totalFrames: number;
private lowFPSCallback: ((fps: number) => void) | null = null;
constructor(totalFrames: number = 60) {
const http = require('http');
const MAX_AGE = 5; // seconds
const STALE_WHILE_REVALIDATE = 200; // seconds
const server = http.createServer((req, res) => {
// Set cache control headers
res.setHeader('Cache-Control', `max-age=${MAX_AGE}, stale-while-revalidate=${STALE_WHILE_REVALIDATE}`);
@wesbos
wesbos / Bluesky.tsx
Created November 5, 2024 17:05
Bluesky RSC
export async function BlueSkyPost() {
const url = new URL('https://bsky.app/profile/danabra.mov/post/3la62zxt4rs2j');
const details = url.pathname.split('/').filter(Boolean).reduce((acc, part, index, pathParts) => {
if (index % 2 === 0 && pathParts[index + 1]) {
acc[part] = pathParts[index + 1];
}
return acc;
}, {} as Record<'post' | 'profile' | string, string>);
const endpoint = new URL('https://public.api.bsky.app/xrpc/app.bsky.feed.getPostThread');
const params = new URLSearchParams();
import Anthropic from '@anthropic-ai/sdk';
import { Glob } from 'bun';
export const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_KEY
});
const glob = new Glob("./txt/*.txt");
type Page = {
"workbench.editor.customLabels.patterns": {
"**/routes/**/+page.svelte": "${dirname(1)}/${dirname}",
"**/routes/**/+page.server.ts": "/${dirname} [server]",
"**/app/**/page.tsx": "${dirname}.${extname}",
"**/app/**/layout.tsx": "${dirname}/layout.${extname}"
}
@wesbos
wesbos / logger.js
Created January 8, 2024 15:55
console.log line numbers in Node.js
// Use like this: node --import logger.js yourapp.js
import path from 'path';
const { log } = console;
[`debug`, `log`, `warn`, `error`, `table`, `dir`].forEach((methodName) => {
const originalLoggingMethod = console[methodName];
console[methodName] = (...args) => {
const originalPrepareStackTrace = Error.prepareStackTrace;
Error.prepareStackTrace = (_, stack) => stack;
class PathMe {
moves: string[] = [];
constructor() {
this.moves = [];
return this;
}
moveTo(x: number, y: number) {
import dotenv from "dotenv";
import { readFile, writeFile } from 'fs/promises';
dotenv.config();
import { Configuration, OpenAIApi } from "openai";
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
export const openai = new OpenAIApi(configuration);
@wesbos
wesbos / settings.json5
Created December 21, 2022 16:30
VS Code Italic Comments
{
"editor.tokenColorCustomizations": {
// just one
"comments": {
"fontStyle": "italic",
},
// multiple scopes
"textMateRules": [
{
"scope": [