Skip to content

Instantly share code, notes, and snippets.

View owen2345's full-sized avatar

Owen Peredo Diaz owen2345

View GitHub Profile
@owen2345
owen2345 / ruby.yaml
Created August 12, 2020 15:59
micro services + micro frnotends CI
name: Content System
on:
push:
branches:
- master
- develop
- staging
pull_request:
@owen2345
owen2345 / repair_nested_params.rb
Last active June 19, 2020 15:21
Repair numbers converted into string (Rails 4)
repair_nested_params({id: '11', age: '25'}) # Sample
def repair_nested_params(obj)
obj.each { |key, value| obj[key] = parse_value(value) }
end
def parse_value(value)
return repair_nested_params(value) if value.is_a?(Hash)
return value.map(&method(:parse_value)) if value.is_a?(Array)
return value unless value.is_a?(String)
@owen2345
owen2345 / delayed_job_ext.rb
Last active March 20, 2020 10:36
Delayed job: uniqueness support, sequential execution support, keep successful jobs
# 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
@owen2345
owen2345 / _myslider.html.erb
Last active March 13, 2020 08:32
Camaleon CMS Create Own Custom Fields (Complex)
#/themes/e_shop/views/custom_field/_my_slider.html.erb
<div class="group-input-fields-content" data-callback-render="render_my_custom_slider">
<div class="form-group">
<label>Image:</label>
<div class="input-group">
<input data-dimension="<%= field.options[:dimension] %>" data-versions="<%= field.options[:versions] %>" data-thumb_size="<%= field.options[:thumb_size] %>" type="url" name="<%= field_name %>[<%= field.slug %>][values][][image]" class="data-error-place-parent image_field form-control <%= "required" if field.options[:required].to_s.to_bool %>"/>
<span class="input-group-addon btn_upload" onclick="load_upload_image_field($(this).prev());"><i class="fa fa-upload"></i> <%= t('camaleon_cms.admin.button.upload_image')%> <%= "(#{field.get_option('dimension')})" if field.get_option('dimension').present? %></span>
</div>
</div>
<div class="clearfix">
@owen2345
owen2345 / uniqueness_job.rb
Created September 20, 2019 08:29
Sidekiq uniqueness jobs. Permits to avoid duplicated jobs already enqueued or scheduled.
# 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)
@owen2345
owen2345 / Gemfile
Created August 31, 2019 16:51
Multiple man subscribe testing
gem 'multiple_man'
gem 'bunny-mock'
@owen2345
owen2345 / result.yaml
Last active May 8, 2019 09:40
Yaml does not permit to share values between documents in the same file. Then this script helps with that problem.
---
apiVersion: extensions/v1beta1
kind: Deployment
env: &env_vars
val1: "val1"
val2: "val2"
---
apiVersion: extensions/v1beta1
kind: Service
env:
@owen2345
owen2345 / secrets_generator.py
Created May 8, 2019 09:29
Kubernetes secrets generator from env vars (secrets.yml content and env vars for deployment.yml). Original code here: https://github.com/TelluIoT/kubernetes-env-to-secrets/blob/master/README.md
# 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
#
# 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
@owen2345
owen2345 / sqlite3-to-mysql.rb
Last active December 15, 2016 14:01
Camaleon CMS migrate sqlite3 to mysql DB
#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)