Skip to content

Instantly share code, notes, and snippets.

View palkan's full-sized avatar

Vladimir Dementyev palkan

View GitHub Profile
@palkan
palkan / actioncable_streaming_patch.rb
Created November 9, 2016 11:46
ActionCable Streaming Patch
module ActionCable::Channel::Streams
def worker_pool_stream_handler(broadcasting, user_handler, coder: nil)
{ connection: connection, id: @identifier.to_json }
end
end
class ActionCable::SubscriptionAdapter::SubscriberMap
def invoke_callback(callback, message)
callback[:connection].send(:websocket).transmit(
"{\"identifier\": #{callback[:id]},\"message\": #{message}}"
@palkan
palkan / ac_streams_bench.rb
Created November 9, 2016 11:39
ActionCable Streaming Benchmark
# rubocop disable:all
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
@palkan
palkan / postgres_queries_and_commands.sql
Last active December 5, 2019 13:01 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- kill running query
SELECT pg_cancel_backend(procpid);
-- kill idle query
@palkan
palkan / after_commit_conditional.rb
Created December 22, 2015 09:57
CounterCulture skip after commit
def _after_commit_hook
super unless skip_after_commit_hook
@_counter_culture_active = false
end
def skip_after_commit_hook
false
end
@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 / shared_feature.rb
Created December 19, 2015 18:52
Capture exceptions with screenshots (feature specs)
shared_context "feature", type: :feature do
after(:each) do |example|
next unless example.exception
meta = example.metadata
next unless meta[:js] == true
filename = File.basename(meta[:file_path])
line_number = meta[:line_number]
screenshot_name = "screenshot-#{filename}-#{line_number}.png"
save_screenshot(screenshot_name) # rubocop:disable Lint/Debugger
puts meta[:full_description] + "\n Screenshot: #{screenshot_name}"
@palkan
palkan / Guardfile
Created December 19, 2015 16:50
Guardfile for Rails
# По умолчанию запускаем только необходимых для тестов наблюдателей,
# то есть всех, кроме server.
# Для запуска всех: bundle exec guard -g default
scope groups: ['specs']
group 'specs' do
# запускаем тесты и использованием Spring
guard :rspec, cmd: "bundle exec spring rspec" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)
@palkan
palkan / pusher.erl
Created December 4, 2015 12:37
Video chunks pusher for delivery
Pusher = fun(Client, Name, Size) -> F = fun(_, _, _, _, 0) -> io:format('done'); (Fun, C, N, I, Size) -> Segment = "../dash-examples/"++N++integer_to_list(I)++".m4s", io:format("Segment: ~s~n", [Segment]), {ok, B} = file:read_file(Segment), de_client:send(C, {binary, B}), timer:sleep(500), Fun(Fun, C, N, I+1, Size - 1) end, InitName = "../dash-examples/"++Name++"init.mp4", io:format("Init file: ~s~n", [InitName]), {ok, I} = file:read_file(InitName), de_client:send(Client, {binary, I}), timer:sleep(1500), F(F, Client, Name, 1, Size) end.
@palkan
palkan / main.rb
Last active September 30, 2015 07:33
Rails Issue 21765
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rack', github: "rack/rack"
@palkan
palkan / main.rb
Last active August 29, 2015 14:26
Issue 21116
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'arel', github: 'rails/arel'