Skip to content

Instantly share code, notes, and snippets.

@dpaluy
Last active May 20, 2025 07:33
Show Gist options
  • Select an option

  • Save dpaluy/06e0bfe183729e175f912362eaa1ef76 to your computer and use it in GitHub Desktop.

Select an option

Save dpaluy/06e0bfe183729e175f912362eaa1ef76 to your computer and use it in GitHub Desktop.
Setup Script for Rails application
#!/usr/bin/env bash
set -euo pipefail
################################################################################
# VARIABLES – adjust only if you really need something different
################################################################################
NODE_VERSION="22.12.0" # must match Dockerfile
PNPM_VERSION="latest" # use a specific version if you prefer
PARALLEL_JOBS="$(nproc)" # bundler / compile jobs
################################################################################
# APT PACKAGES – runtime + build deps needed by the Rails stack
################################################################################
apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -yqq --no-install-recommends \
build-essential \
git curl wget ca-certificates gnupg2 dirmngr xz-utils vim unzip \
libssl-dev libreadline-dev zlib1g-dev libyaml-dev \
libjemalloc2 libjemalloc-dev \
libvips-dev libheif-dev libde265-dev \
libpq-dev libpq5 postgresql-client \
default-libmysqlclient-dev \
freetds-dev freetds-bin tdsodbc unixodbc unixodbc-dev \
libsqlite3-dev \
python-is-python3 pkg-config \
postgresql-16 postgresql-common
rm -rf /var/lib/apt/lists/* # keep the image lean
################################################################################
# NODE + PNPM – mirrors the Dockerfile (node-build via NVM is the lightest path)
################################################################################
echo "▶ Building Node ${NODE_VERSION}…"
curl -fsSL https://github.com/nodenv/node-build/archive/refs/heads/master.tar.gz | tar -xz -C /tmp/
NODE_BUILD_DIR="$(find /tmp -maxdepth 1 -type d -name 'node-build-*' | head -n 1)"
"$NODE_BUILD_DIR/bin/node-build" "${NODE_VERSION}" /usr/local/node
rm -rf "$NODE_BUILD_DIR"
export PATH="/usr/local/node/bin:$PATH"
npm install -g "pnpm@${PNPM_VERSION}"
################################################################################
# RUBYGEMS – system & bundler (Ruby 3.4.4 already pre-installed on Codex)
################################################################################
gem update --system --no-document
gem install bundler --no-document
################################################################################
# PROJECT DEPENDENCIES
################################################################################
bundle config set jobs "${PARALLEL_JOBS}"
bundle install --retry 3
if [[ -f pnpm-lock.yaml ]]; then
pnpm install --frozen-lockfile
else
npm install
fi
################################################################################
# PLAYWRIGHT BROWSERS – used for system tests
################################################################################
echo "▶ Installing Playwright Chromium…"
npx playwright install chromium
################################################################################
# DATABASE & BOOTSTRAP
################################################################################
###############################################################################
# PostgreSQL local cluster + “dev” superuser
###############################################################################
pg_ctlcluster --skip-systemctl-redirect 16 main start
PG_USER="dev"
PG_PASS="devsecret"
sudo -u postgres psql -v ON_ERROR_STOP=1 <<SQL
DO \$\$ BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = '${PG_USER}') THEN
CREATE ROLE ${PG_USER} SUPERUSER LOGIN PASSWORD '${PG_PASS}';
ELSE
ALTER ROLE ${PG_USER} WITH PASSWORD '${PG_PASS}';
END IF;
END \$\$;
SQL
# Correct exports
export DB_USER="${PG_USER}"
export DB_PASSWORD="${PG_PASS}"
export DB_HOST="localhost"
export DB_PORT="5432"
###############################################################################
# Rails tasks
###############################################################################
bundle exec bootsnap precompile --gemfile
bin/rails db:prepare # now uses dev / devsecret
echo "✅ Codex environment ready for Ruby 3.4.4 Rails application!"

System – "What would you like the assistant to know?"

  1. Always ask yourself “Why?” before answering.
    • Identify the user’s underlying goal and the real-world impact of your reply.
  2. Default to first-principles reasoning.
    • Break complex tasks into bite-sized steps; state assumptions; surface trade-offs.
  3. If a request is ambiguous, ask up to 3 concise clarifying questions instead of guessing.
  4. Stay tool-agnostic.
    • Offer generic patterns and decision criteria; mention concrete libraries or frameworks only if the user has already done so.
  5. Treat every answer as reusable documentation.
    • Prefer self-contained explanations and links to canonical resources over one-off tips.

Assistant – "How would you like the assistant to respond?"

  1. Two-phase structure for all substantive answers:
    • Snapshot – no more than 3 lines summarizing the core solution.
    • Details – numbered or bulleted steps the user can follow or copy into a prompt, CLI, or code editor.
  2. Tone: professional but approachable; avoid jargon unless the user has used it first.
  3. Length: aim for brevity; include depth only where it moves the task forward.
  4. Examples over theory. Whenever feasible, show a minimal working snippet, command, or pseudo-code block.
  5. No hidden state. If you rely on an assumption, say it out loud. If you’re uncertain, label it and suggest how to verify.
@dpaluy
Copy link
Author

dpaluy commented May 20, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment