Skip to content

Instantly share code, notes, and snippets.

@sephraim
sephraim / buy_now.html.erb
Last active April 14, 2025 17:46
[Rails button_to / link_to params] Pass query params using link_to or hidden params using button_to
<!-- Pass hidden params to the button_to -->
<%= button_to "Buy Now", stripe_embedded_checkout_path, params: { price_id: price.id }, method: :get, data: { turbo: false } %>
<!-- Pass query params to the link_to -->
<%= link_to "Buy Now", stripe_embedded_checkout_path(price_id: price.id), method: :get, data: { turbo: false } %>
<!-- both methods allow you to access params[:price_id] in the controller -->
@sephraim
sephraim / run.sh
Last active March 18, 2025 21:07
[Run your app in Docker without docker-compose] ssh into your app's bash terminal
NAME=my-app-name && docker build -t $NAME -f .devcontainer/docker/Dockerfile . && docker run -it --rm $NAME bash
@sephraim
sephraim / dbfg.sh
Created March 12, 2025 22:45
[Kill all running docker containers & reclaim space]
alias dbfg="docker rm -f \$(docker ps -aq); docker system prune -f"
@sephraim
sephraim / sync-branches.sh
Created February 19, 2025 09:56
[Sync master (main) / develop branches in git]
# NOTE: THE FOLLOWING IS FOR *NON-FORKED* REPOS ONLY.
# "origin" WILL REFER TO THE *MAIN* REPO, NOT A FORK.
# AND THERE IS NO "upstream".
# Prep...
git fetch origin
# DEVELOP
git checkout develop
git pull --rebase origin develop # (1.) pull in latest changes from remote "develop"
@sephraim
sephraim / Dockerfile
Created November 6, 2024 19:06
[Installing node / npm in a Ruby Docker image]
# STAGE 1: Initial setup
FROM ruby:2.6.10 as base
WORKDIR /app
# Use a bundler version that works for both this version of Ruby and (if applicable) the version of Rails being used
# NOTE: The RubyGems version that comes with Ruby 2.6 contains a bug and must be updated to v3.2.3.
# Use a bundler version that works for both this version of Ruby and (if applicable) the version of Rails being used
# NOTE: Bundler v2.4.22 is the last version that works with Ruby 2.6.
# RubyGems v3.4.22 is the last version that works with Ruby 2.6.
@sephraim
sephraim / README.md
Last active November 6, 2024 19:16
[Requiring and using the 'debug' gem in a Ruby script]

Ruby 'debug' gem

To require and use:

require 'debug/prelude'

# Then to use...
debugger
@sephraim
sephraim / upload-artifacts.yml
Last active August 21, 2024 21:01
[GitHub Actions - Upload artifacts]
# FILE: .github/workflows/upload-artifacts.yml
name: Upload artifacts on failure
on:
push:
branches:
- main
- master
- develop
@sephraim
sephraim / lint-shell-scripts.yml
Created August 21, 2024 20:39
[GitHub Actions - Lint shell scripts with Differential Shellcheck]
# FILE: .github/workflows/lint-shell-scripts.yml
# SOURCE: https://github.com/koalaman/shellcheck/wiki/GitHub-Actions
name: Lint shell scripts
on:
push:
branches:
- main
- master
- develop
@sephraim
sephraim / .redocly.yml
Last active June 7, 2024 14:28
[OpenAPI / YAML / JSON linting] Using Spectral, Redocly CLI, and Vacuum
# More info on Redocly config: https://redocly.com/docs/cli/configuration/
# Redocly API guidelines builder: https://redocly.com/api-governance/
# List of Redocly built-in linting rules: https://redocly.com/docs/cli/rules/built-in-rules/
# Redocly comparison to Spectral (another popular OpenAPI linter): https://redocly.com/docs/cli/guides/migrate-from-spectral/
apis:
perks@v1:
root: optum-perks-online-care-api-spec.yml
extends:
- recommended-strict
rules:
@sephraim
sephraim / stub_date_time_spec.rb
Created April 5, 2024 21:55
[Stub date / time in Ruby / Rails RSpec tests]
before(:example) do
time = Time.new(2024, 3, 18, 17, 0, 0)
allow(Time).to receive(:now).and_return(time)
allow(Date).to receive(:today).and_return(time.to_date)
end