go
package export

import (
	"encoding/csv"
	"log"
	"net/http"

Streaming Large CSV Exports in Go Without Buffering the Whole File

go http csv
by codesnips 3 tabs
ruby
require "securerandom"
require "digest"

class SlidingWindowLimiter
  Result = Struct.new(:allowed, :count, :remaining)

Sliding-Window API Rate Limiting with Rack Middleware and Redis

ruby rack redis
by codesnips 4 tabs
rust
use std::time::Duration;
use rand::Rng;

#[derive(Clone, Debug)]
pub struct BackoffPolicy {
    pub base_delay: Duration,

Exponential Backoff With Jitter for Retrying Fallible Async Operations in Rust

rust tokio async
by codesnips 3 tabs
python
import random
from dataclasses import dataclass
from typing import Iterator


@dataclass(frozen=True)

Retry Flaky HTTP Requests with Exponential Backoff and Full Jitter in Python

python requests retry
by codesnips 3 tabs
java
package com.example.security;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.io.Decoders;

Stateless JWT Authentication Filter and SecurityFilterChain in Spring Boot

java spring-boot spring-security
by codesnips 3 tabs
yaml
auth:
  - authentication required for non-public endpoints
  - authorization rules documented and tested
data:
  - secrets stored outside source control
  - encryption in transit enabled

Security review checklist for production readiness of new services

security-review checklist production-readiness
by Kai Nakamura 1 tab
bash
#!/usr/bin/env bash
set -euo pipefail

cosign sign --key env://COSIGN_PRIVATE_KEY ghcr.io/example/codesnips:${GITHUB_SHA}
cosign verify --key env://COSIGN_PUBLIC_KEY ghcr.io/example/codesnips:${GITHUB_SHA}

Signed release artifacts with cosign for software supply chain trust

supply-chain cosign signing
by Kai Nakamura 1 tab
plaintext
example.com.          IN TXT  "v=spf1 include:_spf.google.com -all"
default._domainkey    IN TXT  "v=DKIM1; k=rsa; p=MIIBIjANBgkqh..."
_dmarc.example.com.   IN TXT  "v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com; adkim=s; aspf=s"

Email security baseline with SPF DKIM and DMARC records

email-security spf dkim
by Kai Nakamura 1 tab
yaml
severities:
  sev1: customer-impacting active compromise or confirmed data exposure
  sev2: high risk suspicious activity with potential customer impact
  sev3: contained issue with low current impact

first_hour:

Incident response severity matrix and first hour checklist

incident-response runbooks security-operations
by Kai Nakamura 1 tab
ruby
class CspReportsController < ActionController::API
  def create
    Rails.logger.warn({
      event: 'csp_report',
      report: params.to_unsafe_h,
      ip: request.remote_ip,

CSP report endpoint for monitoring attempted browser policy violations

csp reporting browser-security
by Kai Nakamura 1 tab
ruby
user = User.find_by(email: params[:email].to_s.downcase.strip)

if user
  raw_token = SecureRandom.urlsafe_base64(32)
  user.password_resets.create!(token_digest: Digest::SHA256.hexdigest(raw_token), expires_at: 30.minutes.from_now)
  PasswordResetMailer.with(user: user, token: raw_token).deliver_later

Password reset flow that avoids user enumeration and token leaks

password-reset account-enumeration authentication
by Kai Nakamura 1 tab
swift
final class PinnedSessionDelegate: NSObject, URLSessionDelegate {
    func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        guard let serverTrust = challenge.protectionSpace.serverTrust else {
            completionHandler(.cancelAuthenticationChallenge, nil)
            return
        }

Client certificate pinning considerations for mobile apps

pinning mobile-security tls
by Kai Nakamura 1 tab