Skip to content

Instantly share code, notes, and snippets.

View valdemarua's full-sized avatar

Volodymyr valdemarua

View GitHub Profile
@valdemarua
valdemarua / retry_helpers.rb
Created September 24, 2024 17:12
Retry on failure helper
# Usage examples:
#
# 1. Basic usage with default parameters:
#
# retry_on_failure do
# expect(some_condition).to be_true
# end
#
# result = retry_on_failure do
# expect(some_condition).to be_true
@valdemarua
valdemarua / New Rails App Settings
Last active May 3, 2024 14:13
New Rails App Settings
– Generate new app:
– Add Standardrb/Rubocop
– Tune generators
# application.rb
config.generators do |g|
g.javascripts false
g.stylesheets false
@valdemarua
valdemarua / request_helpers.rb
Last active April 6, 2024 14:12
RSpec request helper
# /spec/support/request_helpers.rb
#
# Include helper inside rails_helper.rb file:
#
# config.include RequestHelpers, type: :request
#
module RequestHelpers
#
# response body: {"data": { "id": 1 }}
#
@valdemarua
valdemarua / useQueryState.js
Last active November 13, 2022 13:53
React Hooks
// Dependencies: react-router, qs
//
// Usage:
//
// const [taskState, setTaskState] = useQueryState("state");
//
// setTaskState("new") => /tasks?state=new
import { useCallback } from "react"
import { useHistory, useLocation } from "react-router-dom"
@valdemarua
valdemarua / .rubocop-rails.yml
Last active December 23, 2023 13:28
Rubocop + Standardrb + Rubocop Rspec
# .rubocop-rails.yml

#Деградация функциональности http://joxi.ru/DxXOU4wyTJCzLlQsA7o Есть фичи у проекта - есть критичные вещи, есть такие что можно пожертвовать чем-то При проектировании архитектуры нужно учесть возможные фоллбеки Все доп, фичи можно отключить или не использовать в ситуации крайней нагрузки

#Масштабирование Нагрузка растет нужно мастабироваться

@valdemarua
valdemarua / RailsAdmin.md
Created April 25, 2018 08:25 — forked from stevenyap/RailsAdmin.md
Rails Admin

Extracting model configuration

# app/models/booking.rb
class Booking
  include RailsAdmin::Booking
end

# app/models/concerns/rails_admin/booking.rb
module RailsAdmin::Booking
@valdemarua
valdemarua / carrierwave.rb
Created October 23, 2017 16:41 — forked from iqbalhasnan/carrierwave.rb
carrierwave mini_magick image processing - quality, strip, exif rotation, gaussian blur, interlace
#config/initializers/carrierwave.rb
module CarrierWave
module MiniMagick
# Rotates the image based on the EXIF Orientation
def exif_rotation
manipulate! do |img|
img.auto_orient
img = yield(img) if block_given?
img
end
@valdemarua
valdemarua / contrasting_text_color.rb
Created October 10, 2017 14:07 — forked from charliepark/contrasting_text_color.rb
calculate contrast color in Ruby
def convert_to_brightness_value(background_hex_color)
(background_hex_color.scan(/../).map {|color| color.hex}).sum
end
def contrasting_text_color(background_hex_color)
convert_to_brightness_value(background_hex_color) > 382.5 ? '#000' : '#fff'
end