Skip to content

Instantly share code, notes, and snippets.

View palkan's full-sized avatar

Vladimir Dementyev palkan

View GitHub Profile
@palkan
palkan / README.md
Last active October 3, 2024 21:30
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
@palkan
palkan / Gemfile
Last active April 25, 2024 14:23
RSpec profiling with RubyProf and StackProf
gem 'stackprof', require: false
gem 'ruby-prof', require: false
@palkan
palkan / README.md
Created January 24, 2022 13:29
Rails boot time profiling

Add the following to application.rb:

$icallbacks = []
$icallbacks.define_singleton_method(:print) do
  puts sort_by { |(a, b)| -b }.map { |(a, b)| "#{b}\t\t#{a}" }.join("\n")
end

ActiveSupport::Notifications.subscribe("load_config_initializer.railties") do |event|
 $icallbacks << [event.payload[:initializer], event.duration]
# frozen_string_literal: true
require "benchmark_driver"
source = <<~RUBY
class Hash
def symbolize_keys
transform_keys { |key| key.to_sym rescue key }
end
@palkan
palkan / application_view_component.rb
Last active March 2, 2024 18:06
[ViewComponent] html_option
# From https://evilmartians.com/chronicles/viewcomponent-in-the-wild-embracing-tailwindcss-classes-and-html-attributes
class ApplicationViewComponent < ViewComponentContrib::Base
# Move default attrs to a constants so we can re-use it
EMPTY_ATTRS = {}.freeze
class << self
def html_option(name, default: nil, **opts)
if default
opts[:type] = proc { default.merge(_1) }
end
@palkan
palkan / 01_readme.md
Last active January 15, 2024 10:32
Docker Dev