Skip to content

Instantly share code, notes, and snippets.

View palkan's full-sized avatar

Vladimir Dementyev palkan

View GitHub Profile
@palkan
palkan / .rubocop_rails.yml
Created March 18, 2020 20:25
rubocop-rails config
# Based on removed standard configuration:
# https://github.com/testdouble/standard/commit/94d133f477a5694084ac974d5ee01e8a66ce777e#diff-65478e10d5b2ef41c7293a110c0e6b7c
require:
- rubocop-rails
Rails/ActionFilter:
Enabled: true
EnforcedStyle: action
Include:
@palkan
palkan / .rubocop_rspec.yml
Last active March 22, 2022 12:44
rubocop-rspec config
require:
- rubocop-rspec
# Disable all cops by default,
# only enable those defined explcitly in this configuration file
RSpec:
Enabled: false
RSpec/Focus:
Enabled: true
@palkan
palkan / tracer.rb
Created February 13, 2020 13:35
[GraphQL] verify batch load
# frozen_string_literal: true
module Graphql
# This module implements the functionality to track whether the batch loading is
# required for a field to solve N+1 problem.
#
# If you want to check whether a particular field doesn't use batch loading in vain,
# mark it with `verify_batch_load: true` option.
#
# By default, it logs the following information when detects a possible N+1 (thus, confirms that batch loading is required).
@palkan
palkan / pp.rb
Created February 13, 2020 13:21
[GraphQL] @pp profiling
# frozen_string_literal: true
module Directives
class Pp < GraphQL::Schema::Directive
class Profiler < Types::BaseEnum
graphql_name "PpProfiler"
description "Available profilers for @pp directive"
value :mem
value :stack
@palkan
palkan / 00_Readme.md
Last active July 16, 2022 06:50
graphql-ruby fragment caching

PoC: GraphQL Ruby fragment caching

This example demonstrates how we can cache the response fragments in graphql-ruby.

Existing solutions only allow caching resolved values but not all the GraphQL machinery (validation, coercion, whatever).

Caching response parts (in case of Ruby, sub-Hashes) is much more efficient.

Benchmarks

@palkan
palkan / many_vs_flat_map_bench.rb
Last active December 4, 2019 09:04
many vs flat_map bench
# See:
# - https://codon.com/refactoring-ruby-with-monads#multiple-results
# - Rails PR: https://github.com/rails/rails/issues/37875
require "benchmark_driver"
Benchmark.driver do |x|
x.prelude %Q{
Blog = Struct.new(:categories)
Category = Struct.new(:posts)
@palkan
palkan / 01_Readme.md
Last active April 30, 2023 00:03
Backport Rails 6 per-environment credentials

Backport Rails 6 per-environment credentials to Rails 5.2

Rails PR: rails/rails#33521

This patch makes it possible to use per-environment credentials (i.e., config/credentials/staging.yml.enc) in Rails 5.2.

Installation

  • Drop backport_rails_six_credentials.rb and backport_rails_six_credentials_command.rb somewhere, for example, into the lib/ folder
  • Add this line to config/application.rb:
@palkan
palkan / keybase.md
Created June 7, 2019 00:16
keybase.md

Keybase proof

I hereby claim:

  • I am palkan on github.
  • I am palkan (https://keybase.io/palkan) on keybase.
  • I have a public key ASBivWpram8T0sSjr4zNGnRCfvj2TElWUqKfGEqvugkRIwo

To claim this, I am signing this object:

@palkan
palkan / 1_README.md
Last active August 29, 2019 13:26
Railsy Rails Events Store

Railsy Rails Events Store

Since our architecture is modularized, we need a way for our components/engines to communicate with each other.

We do this by adding a pub/sub (or event sourcing) layer to our application via Rails Event Store.

We do not use RES directly but through the railsy-events engine, which wraps RES functionality and provide its own API. That would allow us to replace RES in the future (if necessary) without changing our application code.

Describe events

@palkan
palkan / config.yml
Last active March 3, 2019 18:28
Parcel + GH pages + S3
version: 2.1
workflows:
version: 2
build_and_test:
jobs:
- checkout
- yarn_install:
requires:
- checkout