Skip to content

Instantly share code, notes, and snippets.

@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
@sephraim
sephraim / README.md
Created March 20, 2024 05:33
[Passing an argument to shared examples in RSpec] Here's a VCR example

let is not available in the scope of the shared example group definition, but only in the example (it, specify, scenario) scope.

To pass cassette_name to the shared examples, you can use a method argument instead of let. Here's how you can modify your shared examples and usage:

RSpec.shared_examples 'a vehicle' do |opts|
  use_vcr_cassette(opts[:cassette_name])
end
@sephraim
sephraim / docker_ruby.sh
Last active June 2, 2024 17:29
[Quickly run Ruby container using Docker] Spin up a quick Ruby container with Docker and without Docker Compose
docker run -it --rm -v .:/app ruby:3.2.2 bash
@sephraim
sephraim / checkout_1_file.sh
Last active March 16, 2024 15:17
[Checkout 1 file / commit from branch] Use git `format-patch`, `checkout`, or `cherry-pick`
# STEP 1: Find the latest commit in the branch you want to grab a file from
git log <other-branch>
# STEP 2:
# Option 1: Get 1 file from another branch (preserves author info)
git format-patch -o patches ..<other-branch-latest-commit> -- <path-to-file>
git am patches/*.patch
# This will automatically add commit(s) onto your branch. Squash those commits with:
git rebase -i HEAD~3 # e.g. for 3 commits
# If multiple authors then the author of the earliest commit will become the new author
@sephraim
sephraim / index.html.slim
Created March 14, 2024 16:30
[Rails view test with RSpec + Capybara]
/ # FILE: views/api/keys/index.html.slim.rb
h1 API Keys
table class="table"
thead
tr
th Key
th User
th Description
@sephraim
sephraim / .dockerignore
Created February 21, 2024 21:33
[.dockerignore example]
.git/
/.bundle/
/coverage/
/doc/
/log/*.log
/node_modules/
/output/
/pkg/
/public/uploads/
/public/test/
@sephraim
sephraim / camel_case.rb
Created January 26, 2024 07:35
[Convert PascalCase / camelCase to snake_case]
# Convert a string from PascalCase or camelCase to snake_case
#
# @example
# format_string_key("SearchVault") #=> "search_vault"
# format_string_key("SetPINDirection") #=> "set_pin_direction"
# format_string_key("PINNumber") #=> "pin_number"
# format_string_key("myVaultPINNumber") #=> "my_vault_pin_number"
#
# @param key [String] The key name to convert
# @return [String] The converted string
@sephraim
sephraim / README.md
Last active April 2, 2024 20:21
[Resolving "bundler requires Ruby version >= 3.0.0" in Dockerfile]

If you try to build your Ruby Dockerfile and get the following error(s):

 => ERROR [app base 4/4] RUN gem install bundler                                                                                                                                                                                                  24.1s
------
 > [app base 4/4] RUN gem install bundler:
24.10 ERROR:  Error installing bundler:
24.10 	The last version of bundler (>= 0) to support your Ruby & RubyGems was 2.4.22. Try installing it with `gem install bundler -v 2.4.22`
24.10 	bundler requires Ruby version >= 3.0.0. The current ruby version is 2.6.10.210.
------
@sephraim
sephraim / README.md
Last active January 3, 2024 22:25
[Install Ruby via asdf]

1.) Upgrade asdf itself

If installed via homebrew...

brew update && brew upgrade

If installed via curl...

asdf update