Skip to content

Instantly share code, notes, and snippets.

View palkan's full-sized avatar
✈️
Transcontinental hustle

Vladimir Dementyev palkan

✈️
Transcontinental hustle
View GitHub Profile
@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 / 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 / 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 / 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 / clear_dirs
Created November 13, 2013 09:59
Script to delete directories older than 1 day within target directory. Path to target directory is stored in Erlang application's app.config file as {storage_dir, "path/to/dir"}. Pass path to config as the first argument.
#!/bin/bash
echo [$(date +"%Y-%m-%d %H:%M:%S")] Flush temporary files begins.
SOURCE="${BASH_SOURCE[0]}"
ROOT_DIR=$( dirname "${SOURCE}")
CONFIG=${1}
-module(file_utils).
-export([recursively_list_dir/1,
recursively_list_dir/2,
recursively_del_dir/1,
dir_traversal/2,
dir_traversal/3]).
% @type name() = string() | atom() | binary().
@palkan
palkan / .pryrc
Created April 22, 2015 08:20
Pry $LOAD_PATH hook
# add the current directories /lib and /spec directories to the path if they exist
Pry.config.hooks.add_hook(:before_session, :load_path) do
dir = `pwd`.chomp
%w(lib spec test).map{ |d| "#{dir}/#{d}" }.each { |p| $: << p unless !File.exist?(p) || $:.include?(p) }
end
@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 / docker-clean.sh
Last active November 29, 2016 12:41
Clean Docker Files
#!/bin/bash
# remove exited one-off containers:
docker ps --filter status=dead --filter status=exited -a | grep "_run" | awk '{ print $1 }' | xargs -I@ docker rm -v @
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -I@ docker rmi @
# remove unused volumes
docker volume ls -qf dangling=true | xargs -I@ docker volume rm @
@palkan
palkan / post.md
Created December 7, 2016 16:41
AnyCable post

title: 'AnyCable:the Action Cable Power-Up' category: Back-end date: 2016-12-17 description: 'This article tells the story of the AnyCable project which aims to increase Action Cable performance and functionality.' draft: true authors:

name: 'Vladimir Dementyev'

about: 'Back-end Developer at Evil Martians'