Skip to content

Instantly share code, notes, and snippets.

View ArturT's full-sized avatar

Artur Trzop ArturT

View GitHub Profile
@ArturT
ArturT / upgrade-postgresql-on-macos.md
Last active July 25, 2025 10:44
Upgrade PostgreSQL 14 to 15 to 16 to 17 with brew on macOS (Rails app)

How to upgrade Postgres locally on macOS:

I was using Postgres universal (postgresql package managed by brew) and I had installed postgresql@14 managed version by brew at the same time. This instruction covers what to do if you use postgresql@14 managed by brew or the universal version.

This instruction is inspired by the issue.

You can change the version to the one that you want to upgrade to. It's recommended to upgrade one version at a time.

@ArturT
ArturT / .circleci-config.yml
Last active December 5, 2023 12:01
CircleCI rerun failed tests in RSpec with Knapsack Pro Queue Mode. Thanks to that you can rerun only failed tests instead of rerunning the whole CI build. https://docs.knapsackpro.com/ruby/circleci/ & https://knapsackpro.com
- run:
name: Run tests
command: |
export CIRCLE_TEST_REPORTS=/tmp/test-results
mkdir -p $CIRCLE_TEST_REPORTS
# split slow spec files by test examples
# https://docs.knapsackpro.com/ruby/split-by-test-examples/
export KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES=true
@ArturT
ArturT / spec_helper.rb
Created September 29, 2023 12:15
Knapsack Pro Queue Mode hooks examples
before_suite_block = proc {
puts '+'*100
puts 'RSpec before suite hook called only once'
}
unless KnapsackPro::Config::Env.queue_recording_enabled?
RSpec.configure do |config|
config.before(:suite) do
before_suite_block.call
puts 'Run this only when not using Knapsack Pro Queue Mode'
@ArturT
ArturT / redis_latency.rb
Created September 22, 2023 14:20
Measure Redis latency from inside of Heroku Dyno
# repalce REDIS_CONNECTION with your Redis instance
#
# run this script in Rails console.
# For example start Heroku Dyno with Rails console to measure the Redis latency from inside of the Heroku Dyno
#
# Do you like it? Check what we do: https://knapsackpro.com
rtts = []
100.times do
a = b = 0; a = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond); REDIS_CONNECTION.ping; b = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond); rtt = b - a;
@ArturT
ArturT / spec_helper.rb
Created March 20, 2023 18:56
Preview executed tests in Knapsack Pro Queue Mode for RSpec
KnapsackPro::Hooks::Queue.after_subset_queue do |queue_id, subset_queue_id|
puts '\\'*100
puts 'Executed tests for a batch of tests fetched from Queue API'
Dir.glob(".knapsack_pro/queue/#{queue_id}/*.json").each do |file|
report = JSON.parse(File.read(file))
puts report.inspect
end
puts '/'*100
end
@ArturT
ArturT / README.md
Created October 18, 2021 11:47
rspec-retry only features (capybara) tests on CI
@ArturT
ArturT / openssl-certificate-verify-failed.md
Last active February 24, 2022 17:24
OpenSSL::SSL::SSLError SSL_connect returned=1 errno=0 state=error: certificate verify failed - https://knapsackpro.com/?utm_source=github&utm_medium=gist&utm_campaign=github-gist-openssl-certificate-verify-failed
# bitbucket-pipelines.yml
# this is example using cypress/base docker image
image: cypress/base:10
options:
max-time: 30
# job definition for running E2E tests in parallel with KnapsackPro.com
e2e: &e2e
name: Run E2E tests with @knapsack-pro/cypress
caches:
@ArturT
ArturT / parallel-builds.md
Last active March 5, 2021 22:37
Buildkite parallel builds

Knapsack Pro

A commercially supported version of Knapsack that provides a hosted service for test timing data and additional job distribution modes for Ruby, JavaScript, etc. See the documentation and step-by-step tutorial for Ruby setup instructions and example pipelines. For other programming languages please check integrations.

@ArturT
ArturT / api_controller.rb
Last active July 20, 2023 06:44
How to rescue ActionDispatch::Http::MimeNegotiation::InvalidType in API controller for Rails 6.1+ and render nice JSON error. Learn more how you could run RSpec/Minitest tests faster in Rails app https://docs.knapsackpro.com/2020/how-to-speed-up-ruby-and-javascript-tests-with-ci-parallelisation
# This is example how to rescue from exception ActionDispatch::Http::MimeNegotiation::InvalidType
# and show nice JSON error in your API
module API
class BaseController < ActionController::API
def process_action(*args)
super
rescue ActionDispatch::Http::MimeNegotiation::InvalidType => exception
# set valid Content-Type to be able to call render method below
request.headers['Content-Type'] = 'application/json'
render status: 400, json: { errors: [exception.message] }