Skip to content

Instantly share code, notes, and snippets.

View pfftdammitchris's full-sized avatar
💭
Dreaming

Christopher Tran pfftdammitchris

💭
Dreaming
View GitHub Profile
@pfftdammitchris
pfftdammitchris / snippet-1.ts
Created September 18, 2026 06:04
Next.js Caching Mental Model in 2026: Request Memoization, Data Cache, Full Route Cache, and Router Cache Explained Once and for All - snippet-1.ts
// app/layout.tsx
async function RootLayout() {
const user = await fetch('https://api.example.com/user').then(r => r.json());
return <nav>{user.name}</nav>;
}
// app/page.tsx
async function HomePage() {
const user = await fetch('https://api.example.com/user').then(r => r.json());
return <h1>Welcome, {user.name}</h1>;
@pfftdammitchris
pfftdammitchris / snippet-2.ts
Created September 18, 2026 06:04
Next.js Caching Mental Model in 2026: Request Memoization, Data Cache, Full Route Cache, and Router Cache Explained Once and for All - snippet-2.ts
// Cached indefinitely until manual invalidation
const product = await fetch('https://api.example.com/products/123').then(r => r.json());
// Revalidated every 60 seconds
const inventory = await fetch('https://api.example.com/inventory', {
next: { revalidate: 60 }
}).then(r => r.json());
// Never cached
const user = await fetch('https://api.example.com/user', {
@pfftdammitchris
pfftdammitchris / snippet-3.ts
Created September 18, 2026 06:04
Next.js Caching Mental Model in 2026: Request Memoization, Data Cache, Full Route Cache, and Router Cache Explained Once and for All - snippet-3.ts
// app/products/[id]/page.tsx
// This route is statically generated at build time
export async function generateStaticParams() {
const products = await fetch('https://api.example.com/products').then(r => r.json());
return products.map((p: any) => ({ id: p.id }));
}
export default async function ProductPage({ params }: { params: { id: string } }) {
const product = await fetch(`https://api.example.com/products/${params.id}`).then(r => r.json());
return <h1>{product.name}</h1>;
@pfftdammitchris
pfftdammitchris / snippet-4.ts
Created September 18, 2026 06:04
Next.js Caching Mental Model in 2026: Request Memoization, Data Cache, Full Route Cache, and Router Cache Explained Once and for All - snippet-4.ts
// app/products/page.tsx
export default function ProductsPage() {
return (
<ul>
<li><Link href="/products/1">Product 1</Link></li>
<li><Link href="/products/2">Product 2</Link></li>
</ul>
);
}
@pfftdammitchris
pfftdammitchris / snippet-1.ts
Created September 17, 2026 06:06
Claude Code Headless Mode in 2026: Scripting Autonomous Coding Tasks Without the Interactive Shell - snippet-1.ts
import { execSync } from 'child_process';
function runHeadlessTask(prompt: string): string {
try {
const output = execSync(`claude -p "${prompt.replace(/"/g, '\\"')}"`, {
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe']
});
return output;
} catch (error) {
@pfftdammitchris
pfftdammitchris / snippet-2.ts
Created September 17, 2026 06:06
Claude Code Headless Mode in 2026: Scripting Autonomous Coding Tasks Without the Interactive Shell - snippet-2.ts
// scripts/nightly-refactor.ts
import { exec } from 'child_process';
import { promisify } from 'util';
import { appendFileSync } from 'fs';
const execAsync = promisify(exec);
async function nightlyRefactor(): Promise<void> {
const timestamp = new Date().toISOString();
const logPath = '/var/log/claude-automation/refactor.log';
@pfftdammitchris
pfftdammitchris / snippet-3.yaml
Created September 17, 2026 06:06
Claude Code Headless Mode in 2026: Scripting Autonomous Coding Tasks Without the Interactive Shell - snippet-3.yaml
# .github/workflows/auto-analyze-failures.yml
name: Analyze Test Failures
on:
workflow_run:
workflows: ["Run Tests"]
types: [completed]
jobs:
analyze:
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
@pfftdammitchris
pfftdammitchris / snippet-4.ts
Created September 17, 2026 06:06
Claude Code Headless Mode in 2026: Scripting Autonomous Coding Tasks Without the Interactive Shell - snippet-4.ts
interface ClaudeJsonOutput {
response: string;
files_changed: Array<{
path: string;
operation: 'created' | 'modified' | 'deleted';
diff?: string;
}>;
tokens_used: number;
model: string;
session_id?: string;
@pfftdammitchris
pfftdammitchris / snippet-5.ts
Created September 17, 2026 06:06
Claude Code Headless Mode in 2026: Scripting Autonomous Coding Tasks Without the Interactive Shell - snippet-5.ts
import { spawn } from 'child_process';
function streamHeadlessTask(prompt: string, onChunk: (data: string) => void): Promise<void> {
return new Promise((resolve, reject) => {
const proc = spawn('claude', [
'-p', prompt,
'--stream',
'--no-session-persistence'
]);
@pfftdammitchris
pfftdammitchris / snippet-6.ts
Created September 17, 2026 06:06
Claude Code Headless Mode in 2026: Scripting Autonomous Coding Tasks Without the Interactive Shell - snippet-6.ts
import { spawn } from 'child_process';
import { promises as fs } from 'fs';
interface AgentTask {
id: string;
prompt: string;
workingDir: string;
}
interface AgentResult {