Skip to content

Instantly share code, notes, and snippets.

Avatar

Pavel Shpak ShPakvel

View GitHub Profile
@ShPakvel
ShPakvel / patched_rubocop.rb
Created Dec 13, 2019
A sneaky wrapper around Rubocop that allows you to run it only against the recent changes, as opposed to the whole project.
View patched_rubocop.rb
#!/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:
View Preferences.sublime-settings
{
"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 Aug 29, 2015
Sumatosoft task.
View dicebility.rb
# 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 Oct 15, 2014
Grape permitted_params helper. It works the same as Rails strong params. Only params defined in params block will remain.
View general_helper.rb
module GeneralHelper
def permitted_params
@permitted_params ||= declared(params, include_missing: false)
end
end
@ShPakvel
ShPakvel / Event.rb
Created Jun 25, 2014
Rails 4 enum and simple_form with I18n
View Event.rb
class Event < ActiveRecord::Base
STATUSES = [ :cancelled, :in_progress, :completed, :invoiced ]
enum status: STATUSES
...
end