Skip to content

Instantly share code, notes, and snippets.

View ShPakvel's full-sized avatar

Pavel Shpak ShPakvel

View GitHub Profile
@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
@ShPakvel
ShPakvel / patched_rubocop.rb
Created December 13, 2019 10:24
A sneaky wrapper around Rubocop that allows you to run it only against the recent changes, as opposed to the whole project.
#!/usr/bin/env ruby
# Copyright: https://gist.github.com/skanev/9d4bec97d5a6825eaaf6
# A sneaky wrapper around Rubocop that allows you to run it only against
# the recent changes, as opposed to the whole project. It lets you
# enforce the style guide for new/modified code only, as opposed to
# having to restyle everything or adding cops incrementally. It relies
# on git to figure out which files to check.
#
# Here are some options you can pass in addition to the ones in rubocop:
@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 / Preferences.sublime-settings
Last active August 29, 2015 14:13
Sublime configs
{
"binary_file_patterns":
[
"mobileapp/assets/javascripts/mobile.js",
"mobileapp/assets/javascripts/mobilevendor.js",
"*/elasticsearch_test/*",
"*/elasticsearch/*",
"*/log/*",
"*/tmp/*",
"*.jpg",
@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