Code Snippets

Practical Code Snippets

Ready-to-use examples by tool and language.

Base64 (Node.js)

Encode/decode text to Base64.

// Node.js: Buffer 기반 Base64 인코딩/디코딩
const text = 'hello world'
const encoded = Buffer.from(text, 'utf8').toString('base64')
const decoded = Buffer.from(encoded, 'base64').toString('utf8')

console.log({ encoded, decoded })

JWT verify (Node.js)

Validate required claims and HS256 signature.

// Node.js: 필수 클레임 검증 + HS256 서명
import jwt from 'jsonwebtoken'

const token = jwt.sign(
  { sub: 'user-123', iss: 'dev-tools', aud: 'dev-tools', exp: Math.floor(Date.now() / 1000) + 300 },
  process.env.JWT_SECRET!,
  { algorithm: 'HS256', keyid: 'v1' }
)

jwt.verify(token, process.env.JWT_SECRET!, {
  issuer: 'dev-tools',
  audience: 'dev-tools',
})

CSV → JSON (Python)

Convert with BOM removal and header validation.

# Python: BOM 제거 + 헤더 검증 + JSON 변환
import csv, json

def convert(path):
    with open(path, 'r', encoding='utf-8-sig', newline='') as f:
        reader = csv.DictReader(f)
        if not reader.fieldnames:
            raise ValueError('Missing header row')
        rows = [row for row in reader]
        return json.dumps(rows, ensure_ascii=False, indent=2)

print(convert('data.csv'))

URL regex check (JavaScript)

Limit input length to avoid ReDoS.

// JavaScript: URL 유효성 검사 + 길이 제한으로 ReDoS 방지
const urlPattern = /^(https?:\/\/)([\w.-]+)(:[0-9]+)?(\/.*)?$/i

function isSafeUrl(value) {
  if (value.length > 2048) return false
  return urlPattern.test(value)
}

console.log(isSafeUrl('https://example.com'))

SHA-256 hash

Hash sensitive data with proper encoding/error handling.

// Node.js: crypto로 SHA-256 해시 생성 (hex)
import crypto from 'node:crypto'

function sha256(value) {
  return crypto.createHash('sha256').update(value, 'utf8').digest('hex')
}

console.log(sha256('secret'))

Timestamp conversion

Unix time ↔ ISO string with timezone notes.

// Node.js: Unix 타임 ↔ ISO 변환 (UTC 기준)
const now = Date.now()
const seconds = Math.floor(now / 1000)
const iso = new Date(seconds * 1000).toISOString()
console.log({ seconds, iso })

SQL parameter binding

Use prepared statements to prevent SQL injection.

// Node.js: pg로 파라미터 바인딩 (SQL 인젝션 방지)
import { Pool } from 'pg'
const pool = new Pool()

async function findUser(email) {
  const { rows } = await pool.query('SELECT id, email FROM users WHERE email = $1', [email])
  return rows
}
findUser('test@example.com').then(console.log)

Developer Tools

Explore 80+ free online tools for developers. Base64, JSON, JWT, Regex, and more essentials in one place.

Quick Links

Developer Tools © 2025. All rights reserved.

Most tools run in the browser; tools that require network access only send data when you run them.

코드 스니펫 | Developer Tools