Skip to content

Instantly share code, notes, and snippets.

View kdiogenes's full-sized avatar

Kadu Diógenes kdiogenes

View GitHub Profile
DYNAMIC_URL_OPTIONS_KEY = 'fnix.dynamic_url_options'
module Sidekiq::Middleware::ActionMailerDynamicUrlOptions
# Get the current Action Mailer default URL options and store them in the
# message to be sent to Sidekiq.
class Client
def call(worker_class, msg, queue, redis_pool)
msg[DYNAMIC_URL_OPTIONS_KEY] = Thread.current[DYNAMIC_URL_OPTIONS_KEY]
yield
end
end
class ApplicationController < ActionController::Base
before_action :set_action_mailer_default_url_options
private
def set_action_mailer_default_url_options
Thread.current[DYNAMIC_URL_OPTIONS_KEY] = {
subdomain: request.subdomain,
protocol: request.protocol,
host: request.host_with_port,
class ApplicationMailer < ActionMailer::Base
private
def default_url_options
Thread.current[DYNAMIC_URL_OPTIONS_KEY]
end
end
@kdiogenes
kdiogenes / mjml-rails.example
Last active August 9, 2016 19:32
Rails: template handler example
giving this themplate (action.mjml):
<mj-text>
action content
</mj-text>
rendered with this layout (mailer.mjml):
<mjml>
<mj-body>
@kdiogenes
kdiogenes / linux-4.4.16-1-lts.txt
Created August 10, 2016 13:19
linux: lsmod from linux-4.6.4-1-ARCH and linux-4.4.16-1-lts
ablk_helper 16384 1 aesni_intel
ac 16384 0
aesni_intel 167936 6
aes_x86_64 20480 1 aesni_intel
ahci 36864 3
amd_iommu_v2 20480 1 amdkfd
amdkfd 114688 1
ansi_cprng 16384 0
arc4 16384 2
ath 28672 3 ath9k_common,ath9k,ath9k_hw
@kdiogenes
kdiogenes / cleanup-docker.sh
Last active November 21, 2016 11:41 — forked from mlebkowski/cleanup-docker.sh
docker: cleanup docker disk space https://lebkowski.name/docker-volumes/
#!/bin/bash
# remove exited containers:
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi
# remove unused volumes:
docker volume ls -qf dangling=true | xargs -r docker volume rm
@kdiogenes
kdiogenes / nested_form_controller.rb
Last active February 12, 2017 12:41
vuejs-nested-form: build nested form
helper_method :build_nested_form
def build_nested_form(ignore_params = false)
@nested_form = NestedForm.new
@nested_form.attributes = nested_form_params unless ignore_params
@nested_form.categories = [Category.new] if @nested_form.categories.nil?
@nested_form.categories.each do |category|
category.listener_deadline_values.build if category.listener_deadline_values.empty?
category.presenter_deadline_values.build if category.presenter_deadline_values.empty?
end
@kdiogenes
kdiogenes / error_markup.html.haml
Created February 12, 2017 12:48
vuejs-nested-form: error markup
= f_category.input :name, label: false, error: false, wrapper: 'compact_input_group', wrapper_html: { ':class': '{ "has-error": category.name_errors }' } do
.input-group.col-sm-12
= f_category.input_field :name, 'v-model': 'category.name', class: 'form-control input-sm'
%span.input-group-btn= link_to fa_icon('user-times'), 'javascript:void(0)',
'@click': 'destroy(category)', class: 'btn btn-danger btn-sm'
%span.help-block(v-for='error in category.name_errors') {{ error }}
@kdiogenes
kdiogenes / simple_form_wrapper.rb
Created February 12, 2017 12:49
vuejs-nested-form: simple form wrapper
config.wrappers :compact_input_group, tag: 'div' do |b|
b.use :html5
b.use :placeholder
b.use :input, class: 'form-control'
b.use :hint, wrap_with: { tag: 'p', class: 'compact-help-block' }
end