Skip to content

Instantly share code, notes, and snippets.

View vagra's full-sized avatar

Yan Chen vagra

  • CHINA
  • 21:21 (UTC +08:00)
View GitHub Profile
@vagra
vagra / db.ts
Last active July 26, 2024 12:04
To replace vercel/postgres from the official Next.js tutorial with a local PostgreSQL setup, you simply need to add this /lib/db.ts file, and then change the imports in /lib/data.ts and /seed/router.ts from vercel/postgres to ./db or ../lib/db. Also, don’t forget to run npm install pg.
// db.ts
import { Pool, PoolClient } from 'pg';
import dotenv from 'dotenv';
dotenv.config();
const pool = new Pool({
connectionString: process.env.POSTGRES_URL,
});
@vagra
vagra / routines.go
Last active February 10, 2023 08:47
mutiple goroutines: main -> an inputer -> many worker -> an outputer -> main.
package main
import (
"context"
"fmt"
"sync"
"time"
)
func worker(wg *sync.WaitGroup, ctx context.Context, i int, ci <-chan int, co chan<- string) {