Skip to content

Instantly share code, notes, and snippets.

Nikolay Norkin duderman

Block or report user

Report or block duderman

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View sublime_scope.py
print(view.scope_name(view.sel()[0].begin()))
View gist:cb93f37f6de73acc01b8accce0628970
SHOPS
| id | name | address |
-------------------------------
| 1 | 7Eleven | 1, some st |
| 2 | Wallmart | 2, other st |
Goods
| id | shop_id | name |
-------------------------
| 1 | 1 | Pepsi |
@duderman
duderman / rewind_days.rb
Created Jun 6, 2016
Rewinds old days to current period
View rewind_days.rb
d = Day.maximum(:date)
7.times { |i| Day.where(date: d - i.days).update_all(date: 7.days.from_now.to_date - i.days) }
@duderman
duderman / mysql_adapter.rb
Created Mar 11, 2016
Fix primary_key NULL for rails 2 and mysql 5.7
View mysql_adapter.rb
class ActiveRecord::ConnectionAdapters::MysqlAdapter
NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY"
end
View deep_diff.rb
class Hash
def deep_diff(other)
(self.keys + other.keys).uniq.inject({}) do |memo, key|
left = self[key]
right = other[key]
next memo if left == right
if left.respond_to?(:deep_diff) && right.respond_to?(:deep_diff)
memo[key] = left.deep_diff(right)
View recreate_images_versions.rb
!!cus = CloudUnit.where(slug: 'images', created_at: dates).joins(:items).group('cloud_units.id').having('COUNT(cloud_items.*) <= 1').to_a
!!cus.each { |unit| Resque.enqueue(Jobs::CloudImageCreator, unit.id) if unit.needs_processing? }
!!Component.where(cloud_unit_id: cus.map(&:id)).each { |c| c.box.boxings.each { |bb| bb.boxable.roulette_me } }
View Package Control.sublime-settings
{
"in_process_packages":
[
],
"installed_packages":
[
"Alignment",
"All Autocomplete",
"AngularJS",
"AngularJS (CoffeeScript)",
@duderman
duderman / get_permitted_params.rb
Created Jul 8, 2015
method returns accessible attributes with inheritance and descendants
View get_permitted_params.rb
def permitted_params(klass)
self_attrs = klass.accessible_attributes.reject { |attr| attr =~ /_attributes$/ }.map(&:to_sym)
nested_attrs = klass.nested_attributes_options.keys.map do |nested_klass|
nested_const_klass = nested_klass.to_s.singularize.classify.constantize
{ "#{nested_klass}_attributes".to_sym => permitted_params(nested_const_klass) }
end
types_attrs = klass.descendants.map { |type_class| permitted_params(type_class) }
(self_attrs + (types_attrs || []) + nested_attrs).flatten.uniq.compact
end
View fix_missing_contract.rb
require 'open-uri'
require 'nokogiri'
invoices = Invoice.where(contract_id: nil)
invoices.each do |invoice|
next if invoice.reload.contract
begin
xml_file = open(invoice.archive_file.file_url)
xml = Nokogiri::XML(xml_file)
View load_retail_chain_products_from_csv.rb
def import_retail_chain_products(path)
fail unless File.file? path
imported, failed = [], []
retail_chain_id = 'ed45a234-1d88-481b-8bbd-1ff1ab8ff7a8'
mappings = {
code: { index: 0, type: :string },
full_name: { index: 1, type: :string },
short_name: { index: 2, type: :string },
ru_international_name: { index: 6, type: :string },
retail_chain_registry_concern_id: { index: 4, type: :registry, model: RetailChainRegistry::Concern },
You can’t perform that action at this time.