Skip to content

Instantly share code, notes, and snippets.

View eduardodeoh's full-sized avatar
🏠
Working from home

Eduardo de Oliveira Hernandes eduardodeoh

🏠
Working from home
  • São José do Rio Preto / SP / Brasil
View GitHub Profile
@eduardodeoh
eduardodeoh / lv_upload.ex
Last active July 6, 2020 15:28
LiveView Upload example
#router.ex
# Add specific plug pipeline to router.ex
pipeline :browser_upload do
plug(Plug.Logger)
plug(:accepts, ["html"])
plug(:fetch_session)
plug(:fetch_live_flash)
plug(:put_secure_browser_headers)
end
class MyOperationChild1 < MyOperationMaster
AutoInject = Trailblazer::Operation::AutoInject(MyContainer1)
include AutoInject[moldel_1_class: "api.v1.model.1.class"]
include AutoInject[moldel_2_class: "api.v1.model.2.class"]
end
require 'dry-validation'
SCHEMA = Dry::Validation.Schema do
configure do
config.input_processor = :sanitizer
def self.messages
Dry::Validation::Messages.default.merge(en: { errors: { unique?: "oops not unique" }})
end
@eduardodeoh
eduardodeoh / dry_validation_schemas.rb
Last active May 25, 2016 18:24
dry-validation tests
module ControlKpValidator
# Validation Flow that i need in sequence:
# 1 - uniqueness validation from hash keys (key_phrase) presents here:
# key_phrases: [ { key_phrase: "ph1", weight: 5.3 }, { key_phrase: "ph1", weight: 6.2 } ]
# 2 - value from hash keys (weight) must be between 0 and 4
# key_phrases: [ { key_phrase: "ph1", weight: 5.3 }, { key_phrase: "ph1", weight: 6.2 } ]
# 3 - hash keys "weight" sum must be less than an external value
@eduardodeoh
eduardodeoh / assert_style.rb
Last active December 21, 2015 02:52
Minitest
require 'test_helper'
class FizzBuzzTest < Minitest::Test
def setup
@fb ||= FizzBuzz.new
end
def test_converts_multiples_of_fifteen_to_fizzbuzz
assert_equal 'Buzz', @fb.convert(5)
end
@eduardodeoh
eduardodeoh / gist:b15e15099c71e8b58fae
Created September 30, 2015 21:54 — forked from maetl/gist:4542fc2390eb8701284e
Using transproc to compose various hash transformations and mappings
require 'transproc/all'
require 'addressable/uri'
##
# Convert string keys to symbols
#
transform = Transproc(:symbolize_keys)
data = {
'name' => 'Mark Rickerby',
@eduardodeoh
eduardodeoh / rom_mapper_hash_to_new_hash.rb
Last active September 23, 2015 12:18
Rom Mapper - Hash with keys with object to plain hash
class Parents
include Anima.new(:mother_name, :father_name)
end
person_hash = { name: "eduardo", :parents=>#<Parents mother_name="Mary" father_name="Joe"> }
class PersonHashToNewHash < ::ROM::Mapper
relation :person
register_as :person_to_new_hash
@eduardodeoh
eduardodeoh / 1_create_products.rb
Last active August 26, 2015 18:04 — forked from hakanensari/1_create_products.rb
Sequel + uuid-ossp
Sequel.migration do
up do
run 'CREATE EXTENSION "uuid-ossp"'
create_table :products do
column :id, :uuid, :default => Sequel.function(:uuid_generate_v4), :primary_key => true
end
end
end
#!/bin/sh
#
## This is called to back up the WAL files to the slave.
## This is on top of replication and is used as another
## method to secure data successfully transferring from one
## database server to another.
ARCHIVE_DIR_ON_SLAVE="/var/lib/postgresql/walfiles"
LOG=1
LOG_FILE="/tmp/postgres_wal_archiving.log"
# Idempotent way to build a /etc/hosts file with Ansible using your Ansible hosts inventory for a source.
# Will include all hosts the playbook is run on.
# Inspired from http://xmeblog.blogspot.com/2013/06/ansible-dynamicaly-update-etchosts.html
- name: "Build hosts file"
lineinfile: dest=/etc/hosts regexp='.*{{ item }}$' line="{{ hostvars[item].ansible_default_ipv4.address }} {{item}}" state=present
when: hostvars[item].ansible_default_ipv4.address is defined
with_items: groups['all']