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
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 / 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 / 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']
#!/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
#!/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

Setup

git clone <repo>

clone the repository specified by ; this is similar to "checkout" in some other version control systems such as Subversion and CVS

Add colors to your ~/.gitconfig file: