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
#!/usr/bin/env ruby
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => ':memory:'
)
ActiveRecord::Schema.define do
# include from an initializer
module HstoreAccessor
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def hstore_accessor(hstore_attribute, *keys)
Array(keys).flatten.each do |key|
@eduardodeoh
eduardodeoh / 0_reuse_code.js
Created October 1, 2013 01:05
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@eduardodeoh
eduardodeoh / gist:6361118
Last active December 21, 2015 20:29
Sublime Text 2 - Plugins
http://railsbr.org/t/configuracao-do-sublime-text-2-para-rails/185/2
http://net.tutsplus.com/articles/news/perfect-workflow-in-sublime-text-free-course/
http://technovangelist.com/blog/2013/4/3/i-sublime-a-look-at-my-favorite-sublime-text-plugins
#Base
https://github.com/SublimeLinter/SublimeLinter
https://github.com/SublimeCodeIntel/SublimeCodeIntel
https://github.com/jisaacks/GitGutter
https://github.com/SublimeText/TrailingSpaces
#!/bin/sh
# Locale
echo "Changing locale"
sudo apt-get -y install language-pack-pt
clear
# System update
echo "Updating repositories"
sudo apt-get -y update
@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