This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# config/initializers/delayed_job_ext.rb | |
# unique jobs across workers | |
# Sample: my_model.delay(across_uniq_key: 'article-19').create | |
# Sample: my_model.delay(across_uniq_key: 'article-19').update | |
# Sample: my_model.delay(across_uniq_key: 'article-19').destroy | |
# ==> the jobs will be processed in serial, not in parallel: | |
# can not call update before create or run both at the same time | |
Delayed::Job.class_eval do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'sidekiq/api' | |
module UniquenessJob | |
extend ActiveSupport::Concern | |
included do | |
class << self | |
alias_method :client_push_old, :client_push | |
def client_push(item) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'multiple_man' | |
gem 'bunny-mock' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
apiVersion: extensions/v1beta1 | |
kind: Deployment | |
env: &env_vars | |
val1: "val1" | |
val2: "val2" | |
--- | |
apiVersion: extensions/v1beta1 | |
kind: Service | |
env: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# required python 3 | |
# command: python <location_of_the_file>/secrets_generator.py --env <path_to_env_var_file> --name <secrets_name> | |
#sample: python ./secrets_generator.py --env .env --name my_secrets | |
import copy | |
import argparse | |
import sys | |
import configparser | |
import itertools | |
import base64 | |
from string import Template |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CommentsController < ApplicationController | |
def users_comments | |
# SOLUTION 1: a bit complicated to add pagination and its sql performance is bad when there is a lot of comments, | |
# because the sql query is returning all matched comments | |
@user_comments = Post.all.includes(:comments).eager_load(comments: :author) | |
.where(author: {username: params[:username]}).map(&:comments) | |
.flatten | |
# SOLUTION 2: easy to add pagination and its sql performance is much better | |
@user_comments = Comment.joins(:post, :author).where(author: {username: params[:username]}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Converts multidimensional array into one-dimensional array | |
# @param array_data [Array]: Multidimensional array to be converted into one-dimensional array | |
# @param res [Array]: Internal param control (ignore it) | |
# @sample 1: flatten([1,2,[3,4]]) => [1,2,3,4] | |
# @sample 1: flatten([1,2,[3,4], [[5], [6, [7]]]]) => [1,2,3,4] | |
# @return [Array] Returns a new array that is a one-dimensional | |
def flatten(array_data, res = []) | |
array_data.each{|v| v.is_a?(Array) ? flatten(v, res) : res.push(v) } | |
res |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Take it line by line | |
pending_line = [] | |
query_end = ');' # take care with insert content's ending with ");" | |
ARGF.each do |line| | |
# fix for: mapping values are not allowed in this context at (content used by rails for serialized model attributes) | |
if line.start_with?('INSERT INTO') && !line.strip.end_with?(query_end) | |
pending_line = [line.gsub("\n", '')] | |
next | |
end | |
if pending_line.length > 0 && !line.strip.end_with?(query_end) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- /my_theme/views/admin/settings.html.erb --> | |
<div class="panel panel-default"> | |
<div class="panel-heading"> | |
<h3 class="panel-title"><%= t('.top_offer', default: 'Top Offer') %></h3> | |
</div> | |
<div class="panel-body"> | |
<div class="form-group"> | |
<label><%= t('.top_offer_product', default: 'Offer Product') %></label><br> | |
<%= select_tag "theme_option[top_offer]", options_from_collection_for_select(post_type.posts.public_posts.decorate, :id, :the_title, current_theme.get_option('top_offer')), include_blank: true, class: 'form-control' %> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/paper_trail.rb | |
PaperTrail::Model.module_eval do | |
# return an array of changes for specific attribute (old to newer) | |
# Sample use: Subscriber.find(2).history_from_audits_for(:first_name) | |
# Sample result: [{version: <PaperTrail::Version>, model: <Subscriber>}, {version: <PaperTrail::Version>, model: <MyModel>},....] | |
# Sample print: Subscriber.find(2).history_from_audits_for(:first_name).map{|item| item[:model].first_name } | |
# Required: Diffing Versions of paper trail | |
def history_from_audits_for(attr_name) | |
res = [] | |
self.versions.each do |v| |