Skip to content

Instantly share code, notes, and snippets.

View palkan's full-sized avatar

Vladimir Dementyev palkan

View GitHub Profile
@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
.pi@session_cont
.pi-select.pi data-on-changed="@host.date.text(@this.selected_record().dates)"
...
ul.list
li.item data-id="#{@id}" data-dates="#{@period}"
...
.pi.date@date
@palkan
palkan / gist:731e27c44d730e13ce32
Last active August 29, 2015 14:22
NestedForm + CarrierWave
= nested_form_for answer, remote: true, ... do |f|
...
= f.fields_for :attachments do |attachment_form|
- if attachment_form.object.file.present?
p = attachment_form.object.file.identifier
- else
= attachment_form.label :file
= attachment_form.file_field :file
= attachment_form.link_to_remove "Remove this file"
= f.link_to_add "Add file", :attachments
@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 / gist:c1a08ac2b4f141ab00cd
Last active August 29, 2015 14:24
Rubocop bug report
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rubocop', github: 'bbatsov/rubocop'
GEMFILE
system 'bundle'
end
require 'bundler'
@palkan
palkan / pundited.rb
Created July 25, 2015 13:51
Pundit#authorize_with
# Auhtorize any record to any policy
def authorize_with(klass, record, query = nil)
query ||= "#{action_name}?".to_sym
@_pundit_policy_authorized = @_policy_authorized = true # two vars for forward compatibility
policy = klass.new(pundit_user, record)
unless policy.public_send(query)
error = Pundit::NotAuthorizedError.new("not allowed to #{query} this #{record}")
error.query = query
error.record = record
error.policy = policy
@palkan
palkan / main.rb
Created August 5, 2015 14:36
Persistance#become bug
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'
@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'
@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.