Skip to content

Instantly share code, notes, and snippets.

View palkan's full-sized avatar

Vladimir Dementyev palkan

View GitHub Profile
@palkan
palkan / any_fixture.rb
Created March 28, 2017 21:49
AnyFixture: make DB fixtures from blocks
module AnyFixture
INSERT_RXP = /^INSERT INTO ([\S]+)/
class Cache
attr_reader :store
delegate :clear, to: :store
def initialize
@store = {}
@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 / README.md
Last active April 12, 2025 15:07
remote_capybara.rb

Rails System tests in Docker (Selenium version)

Running Chrome locally

You need ChromeDriver (and Chrome) installed locally and running.

You can install ChromeDriver with Homebrew on MacOS:

brew install chromedriver
@palkan
palkan / connection.rb
Last active April 8, 2025 19:39
Action/AnyCable + Apartment
module ApplicationCable
class Connection < ActionCable::Base::Connection
# we need to keep tenant information for subsequent messages,
# so let's store it as an identifier
identified_by :tenant
def connect
# assuming you store current tenant in session
self.tenant = request.session[:current_tenant]
reject_unauthorized_connection unless tenant
@palkan
palkan / gist:d89757a90cfbeb047c63
Last active January 27, 2025 07:25
Rails debug cheat sheet

Setup

Replace IRB with Pry (in your Gemfile) and Byebug with pry-byebug.

gem 'pry-rails', group: [:development, :test]
gem 'pry-byebug', group: [:development, :test]

Using PRY

@palkan
palkan / README.md
Last active January 3, 2025 14:22
ActionCable over SSE

Action Cable over SSE

This is a demo of leveraging the proposed Action Cable architecture to implement an SSE transport for Action Cable (without changing the user-space code, e.g., Connection and Channel classes).

Start the server by running the following command:

 ruby main.rb

Now, you can connect to Action Cable over SSE via cURL as follows:

@palkan
palkan / .travis.yml
Last active September 26, 2024 20:11
Travis config for TH project
language: ruby
rvm:
- 2.2.3
# Если Travis пишет вам слишком часто, то отключаем email уведомления
notifications:
email: false
# Указываем базу данных
addons:
@palkan
palkan / rubocop_pre_commit_hook
Last active June 19, 2024 10:41 — forked from mpeteuil/rubocop_pre_commit_hook
Rubocop pre-commit hook
#!/usr/bin/env ruby
ADDED_OR_MODIFIED = /^\s*(A|AM|M)/.freeze
changed_files = `git status --porcelain`.split(/\n/)
unstaged_files = `git ls-files -m`.split(/\n/)
changed_files = changed_files.select { |f| f =~ ADDED_OR_MODIFIED }
changed_files = changed_files.map { |f| f.split(" ")[1] }
@palkan
palkan / factory_doctor.rb
Created March 27, 2017 15:42
FactoryDoc: detect useless data generation in tests
module FactoryGirl
module Doctor
module FloatDuration
refine Float do
def duration
t = self
format("%02d:%02d.%03d", t / 60, t % 60, t.modulo(1) * 1000)
end
end
end
@palkan
palkan / Gemfile
Last active April 27, 2024 02:02
FactoryProf: profiler for your FactoryGirl
# if you want to render flamegraphs
gem "stackprof", require: false # required by flamegraph
gem "flamegraph", require: false