Skip to content

Instantly share code, notes, and snippets.

View arel_with_joined_subquery.rb
#
class Article
has_many :nomenclatures, through: :nomenclature_placements, source: :nomenclature
end
class NomenclaturePlacement < ApplicationRecord
belongs_to :nomenclature, class_name: "Mx::Nomenclature",
foreign_key: :mx_nomenclature_id,
touch: true
belongs_to :placement, polymorphic: true
@foton
foton / bi_operations_concern.rb
Last active Jun 10, 2021
Deep Mocking and stubbing with Minitest
View bi_operations_concern.rb
# frozen_string_literal: true
module Mmspektrum
module BiOperations
# ENV["BIGQUERY_PROJECT"] = "mmspektrum-bi"
ENV["BIGQUERY_CREDENTIALS"] = ENV.fetch("GOOGLE_CLOUD_BIGQUERY_KEYFILE")
class BqMockTable
def insert(_data_rows)
OpenStruct.new(insert_errors: [])
@foton
foton / konmari_cs.md
Last active Apr 16, 2021
KonMari metoda úklidu - shrnutí
View konmari_cs.md

KonMari - metoda úklidu podle Marie Kondo

Než začnete, představte si svůj ideální životní styl do co nejpodrobnější a nejbarvitějších detailů. To Vás povede při uklízení.

Uklízejte podle kategorii přes celý byt, nikoliv po místnostech:

  1. oblečení - lze v případě velkého objemu rozdělit dále na

    1. vršky - košile, svetry
    2. dolní kusy - kalhoty, sukně
@foton
foton / base.rb
Created May 2, 2018
Base Service class `.call` with any type of params, returning instace with `#success?`,`#failure?`, `#errors`, `#result` methods.
View base.rb
module Service
class Base
attr_reader :result
def self.call(*args, **keyword_args)
new(*args, **keyword_args).tap do |service|
service.instance_variable_set(
"@result",
service.call
)
@foton
foton / copy_versions_to_new_gemfile.rb
Created Jul 18, 2017
Copy versions from Gemfile.lock to Gemfile (with iternal tests!)
View copy_versions_to_new_gemfile.rb
# frozen_string_literal: true
require 'pry'
module Bundler
class GemVersionsFiller
GEM_NAME_REGEXP = /\* ([\w_-]+) /
IGNORE = %w(xxx)
attr_reader :old_gemfile_lines, :new_gemfile_lines
@foton
foton / rake_rerun_reporter.rb
Last active Apr 26, 2016
minitest reporter, which shows rake rerun commands for failed test at the end
View rake_rerun_reporter.rb
require "minitest/reporters"
module Minitest
module Reporters
class RakeRerunReporter < Minitest::Reporters::DefaultReporter
def initialize(options = {})
@rerun_user_prefix=options.fetch(:rerun_prefix, "")
super
end
View failures_formatters.rb
#@author: Foton (https://github.com/foton)
#this formatter: https://gist.github.com/foton/d317e1b3371021fee964
#Cucumber formatters which displayes only failed steps
#usage: cucumber -f Cucumber::Formatter::Failures features/some.feature
#usage: cucumber -f Cucumber::Formatter::Failures::OneLine features/some.feature
#usage: cucumber -f Cucumber::Formatter::Failures::TwoLines features/some.feature
#usage: cucumber -f Cucumber::Formatter::Failures::StacktraceFirst features/some.feature
require 'cucumber/formatter/pretty'