Skip to content

Instantly share code, notes, and snippets.

View ShPakvel's full-sized avatar

Pavel Shpak ShPakvel

View GitHub Profile
@ShPakvel
ShPakvel / dicebility.rb
Last active August 29, 2015 14:09
Sumatosoft task.
# Sumatosoft task:
# Find probability of sum of thrown dice.
# Input:
# M - dice count (positive integer)
# N - sum (positive integer)
# Output:
# probability (rounded)
#
# Solution:
# Probability equals to count valid permutations of dice values for
@ShPakvel
ShPakvel / general_helper.rb
Created October 15, 2014 18:14
Grape permitted_params helper. It works the same as Rails strong params. Only params defined in params block will remain.
module GeneralHelper
def permitted_params
@permitted_params ||= declared(params, include_missing: false)
end
end
@ShPakvel
ShPakvel / Event.rb
Created June 25, 2014 10:11
Rails 4 enum and simple_form with I18n
class Event < ActiveRecord::Base
STATUSES = [ :cancelled, :in_progress, :completed, :invoiced ]
enum status: STATUSES
...
end