Skip to content

Instantly share code, notes, and snippets.

View ArturT's full-sized avatar

Artur Trzop ArturT

View GitHub Profile
@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] }
@ArturT
ArturT / Equity.md
Created May 14, 2020 17:07 — forked from isaacsanders/Equity.md
Joel Spolsky on Equity for Startups

This is a post by Joel Spolsky. The original post is linked at the bottom.

This is such a common question here and elsewhere that I will attempt to write the world's most canonical answer to this question. Hopefully in the future when someone on answers.onstartups asks how to split up the ownership of their new company, you can simply point to this answer.

The most important principle: Fairness, and the perception of fairness, is much more valuable than owning a large stake. Almost everything that can go wrong in a startup will go wrong, and one of the biggest things that can go wrong is huge, angry, shouting matches between the founders as to who worked harder, who owns more, whose idea was it anyway, etc. That is why I would always rather split a new company 50-50 with a friend than insist on owning 60% because "it was my idea," or because "I was more experienced" or anything else. Why? Because if I split the company 60-40, the company is going to fail when we argue ourselves to death. And if you ju