Skip to content

Instantly share code, notes, and snippets.

View joeywang's full-sized avatar

Joey Wang joeywang

  • reallyenglish.com
  • London
View GitHub Profile
#!/usr/bin/env bash
set -euo pipefail
REPO="${1:-}"
BRANCH="${2:-}"
if [[ -z "$REPO" ]]; then
echo "Usage: $0 <owner/repo> [branch]"
exit 1
fi

Got it — you’ve got two environments:

  • Ruby 4.x on Alpine (musl)
  • Ruby 3.4.8 on Debian (glibc) with Puma

jeprof works best when:

  1. you are actually using jemalloc as the allocator, and
  2. you have symbols available (debug packages help a lot).
#!/bin/bash
# --- Parameter Setup ---
# Priority: 1. Command Line Args, 2. Env Vars, 3. Default (for Project Slug)
TOKEN="${1:-$CIRCLECI_TOKEN}"
SEARCH_STRING="${2:-$TEST_NAME}"
PROJECT_SLUG="${3:-$PROJECT_SLUG}" # Format: github/org/repo
# --- Validation ---
if [ -z "$TOKEN" ]; then

On Kubernetes, the biggest wins usually come from: right-sizing CPU/memory to avoid throttling, matching app concurrency to DB/Redis limits, and separately tuning Puma (web) vs Sidekiq (jobs) so they don’t fight for the same resources.

Below is a practical tuning playbook you can apply immediately.


1) First: avoid the classic k8s performance trap (CPU throttling)

If your pods have a low CPU limit, the Linux CFS scheduler will throttle Ruby, and p95/p99 latency goes bad.

# PR review helper with multi-provider support.
# Highlights:
# - Run one or MANY providers in a single command: -P gemini -P copilot -P openai
# - Provider adapters for: gemini, qwen, codex, copilot (gh extension), openai (stdin), custom (stdin)
# - Carries forward: include/exclude filters, chunking, merged Markdown, PR comments, quiet mode
#
# Requirements (install what you plan to use):
# - gh (GitHub CLI) + authenticated
# - Providers:
# * gemini: $GEMINI_BIN (default: gemini) expects: gemini -p "<prompt @file>"
  1. popup custom window rendered
  2. talk to the endpoint to sign in again.

another solution

  1. iframe to load login page
  2. detect sign or not by comparing the href of the page.

popup a window to ask to reload the page.

# file: config/initializers/connection_validation_test.rb
# This block will be executed only after Active Record has finished loading.
ActiveSupport.on_load(:active_record) do
  # Within this block, it's now safe to modify Active Record components.
  module ActiveRecord
    module ConnectionAdapters
      # It's good practice to check if the class is defined to avoid errors
      # in environments where it might not be (e.g., if you switched to MySQL).
      if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)

The Mystery of the Premature 502: Untangling GCP's Two Health Check Systems

The Scene of the Crime: A Flawless Deployment Ends in a 502

You’ve just deployed a new version of your application to Google Kubernetes Engine (GKE). The CI/CD pipeline glows green, kubectl get pods shows all pods in a Running state, and your deployment is, by all accounts, successful. You navigate to your application's URL, hit refresh, and are greeted by the dreaded 502 Bad Gateway error.

After a few frantic refreshes, the error vanishes and your application loads perfectly. What just happened? You have readiness probes configured. They should have prevented traffic from reaching the pods before they were ready. Yet, somehow, traffic arrived too early.

This is the story of a common and confusing problem in GKE, born from a simple fact: there aren't one, but two separate health check systems at play. Understanding the division between them is the key to solving the mystery of the premature 502.

The Art of the Vanishing Form: Taming Temporary Data in Rails Wizards

Multi-step forms, or "wizards," are a common pattern for guiding users through complex data entry processes like registrations, profile setups, or product configurations. A key challenge in designing these is managing the data collected at each step before the user finally hits that "Submit" button. Where does this transient information live? How do we ensure a smooth user experience without cluttering our database with incomplete records?

One principle should guide us: Don't pollute your primary database with inconsistent, temporary data if you can avoid it. The overhead of storing and then cleaning up these partial records is often more trouble than it's worth. Thankfully, Ruby on Rails offers elegant ways to handle this "in-flight" data, leveraging its powerful object model and session management capabilities.

Let's explore the common strategies and figure out the best path.

The Core Problem: Data in Limbo