Skip to content

Instantly share code, notes, and snippets.

@foton
foton / arel_with_joined_subquery.rb
Last active June 16, 2021 16:44
AREL JOIN SUBQUERY
#
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 June 10, 2021 19:42
Deep Mocking and stubbing with Minitest
# 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 April 16, 2021 16:27
KonMari metoda úklidu - shrnutí

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 08:02
Base Service class `.call` with any type of params, returning instace with `#success?`,`#failure?`, `#errors`, `#result` methods.
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 July 18, 2017 15:18
Copy versions from Gemfile.lock to Gemfile (with iternal tests!)
# 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 April 26, 2016 12:05
minitest reporter, which shows rake rerun commands for failed test at the end
require "minitest/reporters"
module Minitest
module Reporters
class RakeRerunReporter < Minitest::Reporters::DefaultReporter
def initialize(options = {})
@rerun_user_prefix=options.fetch(:rerun_prefix, "")
super
end
#@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'