ruby
class Rack::Attack
  throttle('logins/ip', limit: 5, period: 20.seconds) do |request|
    request.ip if request.path == '/users/sign_in' && request.post?
  end

  throttle('password_reset/email', limit: 3, period: 15.minutes) do |request|

Rate limiting abusive clients with Rack::Attack

rate-limiting rack-attack brute-force
by Kai Nakamura 1 tab
javascript
import { sha256 } from './crypto.js';

const codeVerifier = crypto.randomUUID() + crypto.randomUUID();
sessionStorage.setItem('pkce_verifier', codeVerifier);

const digest = await sha256(codeVerifier);

OAuth 2.0 Authorization Code with PKCE for public clients

oauth2 oidc pkce
by Kai Nakamura 1 tab
ruby
payload = {
  sub: user.id,
  iss: 'https://auth.example.com',
  aud: 'codesnips-api',
  exp: 15.minutes.from_now.to_i,
  iat: Time.now.to_i,

JWT issuance and verification without common footguns

jwt authentication api
by Kai Nakamura 2 tabs
python
from argon2 import PasswordHasher

password_hasher = PasswordHasher(
    time_cost=3,
    memory_cost=65536,
    parallelism=4,

Password hashing with Argon2 and bcrypt migration paths

passwords argon2 bcrypt
by Kai Nakamura 1 tab
ruby
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  before_action :authenticate_user!
end

CSRF protection for Rails and JSON APIs

csrf rails api
by Kai Nakamura 2 tabs
erb
<h1><%= @post.title %></h1>
<p><%= @post.author_name %></p>

<%# Only sanitized rich text should be rendered as HTML %>
<div class="prose"><%= sanitize(@post.body_html, tags: %w[p a ul ol li strong em code], attributes: %w[href]) %></div>

Cross site scripting defense with output encoding and CSP

xss content-security-policy owasp
by Kai Nakamura 3 tabs
ruby
# Vulnerable: user input is concatenated directly into SQL.
email = params[:email]
password = params[:password]

sql = "SELECT * FROM users WHERE email = '#{email}' AND password_hash = '#{password}'"
user = ActiveRecord::Base.connection.execute(sql).first

SQL injection prevention with unsafe and safe query patterns

sql-injection owasp database
by Kai Nakamura 3 tabs
python
import cv2

image = cv2.imread('receipt.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
thresholded = cv2.adaptiveThreshold(

OpenCV image preprocessing for OCR and vision pipelines

opencv image-processing computer-vision
by Dr. Elena Vasquez 1 tab
python
import geopandas as gpd
from shapely.geometry import Point

stores = gpd.read_file('stores.geojson').to_crs(epsg=3857)
customers = gpd.GeoDataFrame(
    customer_df,

Geospatial analysis with GeoPandas for location intelligence

geopandas geospatial analytics
by Dr. Elena Vasquez 1 tab
python
import re

text = 'INC-102301 resolved on 2026-04-06 after payment failure for order ORD-99182.'

patterns = {
    'incident_id': r'INC-[0-9]{6}',

Regular expressions for extracting structured entities from raw text

regex text-processing parsing
by Dr. Elena Vasquez 1 tab
python
import time
import requests
from bs4 import BeautifulSoup

session = requests.Session()
session.headers.update({'User-Agent': 'research-bot/1.0'})

Web scraping pipelines with requests and BeautifulSoup

web-scraping beautifulsoup requests
by Dr. Elena Vasquez 1 tab
sql
WITH ordered_events AS (
  SELECT
    customer_id,
    event_time,
    revenue,
    ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY event_time DESC) AS event_rank,

SQL window functions for feature extraction and behavioral ranking

sql window-functions feature-engineering
by Dr. Elena Vasquez 1 tab