Skip to content

Instantly share code, notes, and snippets.

View ArturT's full-sized avatar

Artur Trzop ArturT

View GitHub Profile
@ArturT
ArturT / terminal.sh
Last active August 30, 2019 16:40
Knapsack Pro - how to start - installation
# for Ruby users (add to Gemfile)
$ gem install knapsack_pro
# for Cypress users
$ npm install --save-dev @knapsack-pro/cypress
# for Jest users
$ npm install --save-dev @knapsack-pro/jest
@ArturT
ArturT / user_controller.rb
Last active January 15, 2020 11:54
Service Objects in Ruby. Related video https://www.youtube.com/watch?v=Ydvu9gcu_iw
class UserController
def create
if params[:ads_source] == 'facebook'
@user = UserCreator.build_for_fb(params)
elsif params[:ads_source] == 'linkedin'
@user = UserCreator.build_for_linkedin(params)
else
raise 'Invalid ad campaign'
end
end
@ArturT
ArturT / how-to-run-tests-faster-on-heroku-ci-with-parallel-dynos.md
Last active May 11, 2019 11:10
How to run tests faster on Heroku CI with parallel dynos

title: How to run tests faster on Heroku CI with parallel dynos

Heroku provides a CI solution out of the box for teams. Heroku CI can run tests in dyno instance for your project. What is more interesting you can run parallel dynos as part of your CI build. This allows you to split tests on parallel dynos to complete CI build faster and save time.

Heroku charges you for seconds spent in runtime for each dyno. It means instead of running your slow test suite on a single dyno you could split it across multiple dynos and pay more or less the same and significantly reduce the CI build time for your project.

@ArturT
ArturT / omni_authorizer.rb
Created April 1, 2019 11:23
Ruby service object examples
class OmniAuthorizer
def self.call(params)
new(SlackAPI.new).call(params)
end
def self.build_for_facebook(params)
new(FacebookAPI.new).call(params)
end
def initialize(api)
@ArturT
ArturT / knapsack_data.rb
Created February 8, 2019 19:21 — forked from manuelpuyol/knapsack_data.rb
This is a simple script used calculate average spec files running time across multiple builds using Knapsack API. It requires that the KNAPSACK_API_TOKEN variable is set. It runs by default for the last 10 builds, but you can customize it passing the number of builds you want as an argument. Lastly, it returns a specs.txt file with the average t…
# frozen_string_literal: true
require 'httparty'
REQUESTED_BUILDS = ARGV[0].to_i || 10
SPEC_FILES = {}
def get(url, options = {})
headers = {
'cache-control': 'no-cache',
@ArturT
ArturT / build.sh
Last active September 27, 2018 20:36
Install node dependencies in async way for multiple projects.
#!/bin/bash
# install dependencies for all react projects in background (async way)
cd app/frontend/app_a && yarn install &
cd app/frontend/app_b && yarn install &
cd app/frontend/app_c && yarn install &
# wait for all processes to finish before move on (sync step)
wait
# config/initializers/dry.rb
require 'dry-struct'
module Types
include Dry::Types.module
end
@ArturT
ArturT / errors.rb
Created February 15, 2018 11:42
Using `+=` will create a local copy of variable instead of updating the reference
# Example 1
errors = []
def add_error_1(errors, arr)
errors += arr # this won't change the errors outside, instead of copy of errors will be created locally
puts "inside of func: #{errors.inspect}"
end
add_error_1(errors, ['an error 1']) # inside of func: ["an error 1"]
puts "outside: #{errors.inspect}" # outside: []
@ArturT
ArturT / bem_mix.html
Last active April 17, 2019 10:31
BEM mix example
<!DOCTYPE html>
<html>
<head>
<style>
/*
* This won't work (Sass syntax - compile first)
*/
.nav {
&__logo {
@ArturT
ArturT / circle.yml
Last active May 1, 2017 14:40
How to auto balance CI build with RSpec in Queue Mode and yarn tests executed only on first CI node
test:
override:
# run yarn tests only on first CI node
# note we will do yarn install on first CI node so other CI nodes can run rspec tests in the mean time
- case $CIRCLE_NODE_INDEX in 0) bundle exec yarn install; yarn flow -- check; yarn test -- --runInBand ;; esac:
parallel: true # Caution: there are 8 spaces indentation!
# Step for Dynamic RSpec allocation
# It will auto balance the whole build
- bundle exec rake knapsack_pro:queue:rspec: