Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
| (• ◡•)| (❍ᴥ❍ʋ)

Yakov annikoff

💭
| (• ◡•)| (❍ᴥ❍ʋ)
View GitHub Profile
View custom_generators.md

The main generator

# lib/generators/rails/policy/policy_generator.rb

module Rails
  module Generators
    class PolicyGenerator < NamedBase
      source_root File.expand_path('templates', __dir__)

      def copy_policy_file
@annikoff
annikoff / issue_patch.rb
Last active May 21, 2019
Redmine IssuePatch
View issue_patch.rb
# Put this file into app/models/concerns
module IssuePatch
extend ActiveSupport::Concern
included do
before_validation :do_some_work
end
def do_some_work
# Your code here
@annikoff
annikoff / bundle_patch.rb
Created May 13, 2019
Prevent specific gem from locking
View bundle_patch.rb
require 'bundler/lockfile_generator'
module GitPatch
def initialize(options)
@skip_locking = options['skip_locking'] === true
super
end
def skip_locking?
@skip_locking
@annikoff
annikoff / arel_any_predicate.rb
Created Feb 8, 2019
An example of how to add a custom predicate to Arel
View arel_any_predicate.rb
module Arel::Predications
def any(right)
Arel::Nodes::Any.new(self, quoted_node(right))
end
end
class Arel::Nodes::Any < Arel::Nodes::Binary
def operator
:'ANY'
end
@annikoff
annikoff / custom_enumerable.rb
Last active May 20, 2020
CustomEnumerable module
View custom_enumerable.rb
module CustomEnumerable
def map(sym = nil)
return enum_for(:map) if !block_given? && sym.nil?
raise SyntaxError if block_given? && !sym.nil?
result = []
each do |item|
result << (sym.nil? ? yield(item) : item.send(sym))
end
result
end
View custom_array_each_method.rb
class Array
def each(sym = nil)
return enum_for(:each) if !block_given? && sym.nil?
raise SyntaxError if block_given? && !sym.nil?
i = 0
while i < self.length
sym.nil? ? yield(self[i]) : self[i].send(sym)
i += 1
end
self
View repair_nested_set_tree.sql
DROP PROCEDURE IF EXISTS tree_recover;
DELIMITER //
CREATE PROCEDURE tree_recover()
MODIFIES SQL DATA
BEGIN
DECLARE currentId, currentParentId CHAR(36);
DECLARE currentLeft INT;
DECLARE startId INT DEFAULT 1;
@annikoff
annikoff / blood_and_сoncrete.sh
Last active Jun 28, 2022
Blood and Concrete monologue
View blood_and_сoncrete.sh
#!/bin/sh
spd-say "You motherfucker, come on you little ass… fuck with me, eh? You fucking little asshole, dickhead cocksucker…You fuckin' come on, come fuck with me! I'll get your ass, you jerk! Oh, you fuckhead motherfucker! Fuck all you and your family! Come on, you cocksucker, slime bucket, shitface turdball! Come on, you scum sucker, you fucking with me? Come on, you asshole"
@annikoff
annikoff / append_text_to_files.sh
Created Dec 1, 2016
This adds \n at the end of the file only if it doesn’t already end with a newline.
View append_text_to_files.sh
for f in **/*.@(rb) ;do
sed -i -e '$a\' $f
done
@annikoff
annikoff / prepend_text_to_files.sh
Last active Dec 1, 2016
Добавление текста в начало файлов
View prepend_text_to_files.sh
for f in **/*.@(rb) ;do
sed -i -e '1i# frozen_string_literal: true\' $f
done