Skip to content

Instantly share code, notes, and snippets.

View brunoluiz's full-sized avatar
🤌

Bruno Luiz Silva brunoluiz

🤌
View GitHub Profile
module.exports = (req, res, next) => {
const ratings = Ratings.schema.validate(req.body)
if (ratings.error) {
return next(ratings.error)
}
req.parsed = ratings.value
return next()
}
const schema = require('./rating-schema')
const result = schema.validate({
username: 'brunoluiz',
rating: 5,
email: 'contact@brunoluiz.net'
})
console.log(result) // result.error will be null
// result.error will show an error due to missing e-mail
const Joi = require('joi')
module.exports = Joi.object().keys({
username: Joi.string(),
rating: Joi.number().integer().min(1).max(5).default(5),
email: Joi.string().email().required()
})
@brunoluiz
brunoluiz / concat-csv.sh
Last active July 18, 2017 20:13
concat-csv.sh
#!/bin/bash
head -1 $2 > $1
for filename in ${@:2}; do sed 1d $filename >> $1; done
@brunoluiz
brunoluiz / .tmux.conf
Last active May 17, 2018 04:15
dotfiles
# Use vim keybindings in copy mode
setw -g mode-keys vi
# start selecting text typing 'v' key (once you are in copy mode)
bind-key -t vi-copy v begin-selection
# copy selected text to the system's clipboard
bind-key -t vi-copy y copy-pipe "xclip -sel clip -i"
# MacOS specific settings (clipboard mostly)
if-shell 'test "$(uname -s)" = Darwin' 'source-file ~/.tmux-macos.conf'
@brunoluiz
brunoluiz / gist:827b6998072a4323649286dea6e4f119
Created May 4, 2017 17:00
rebase when is already rebased
git rebase --onto master HEAD~N
# Where: n = numbers of commit until where the repos are the same
@brunoluiz
brunoluiz / .tmux-macos.conf
Created April 22, 2017 15:41
.tmux-macos.conf
# https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard
# https://robots.thoughtbot.com/tmux-copy-paste-on-os-x-a-better-future
# To copy/paste on OSX just brew install the following
# brew install reattach-to-user-namespace
set-option -g default-command "reattach-to-user-namespace -l zsh"
# load paste buffer to tmux
bind ] run "reattach-to-user-namespace pbpaste | tmux load-buffer - && tmux paste-buffer"
{"lastUpload":"2017-06-14T14:59:25.593Z","extensionVersion":"v2.8.1"}
@brunoluiz
brunoluiz / pre-commit
Last active June 6, 2017 20:56
git-pre-commit-words-hookup
#!/bin/bash
# Author: Nikolaos Dimopoulos
# Based on code by Remigijus Jarmalavičius
# Checks the files to be committed for the presence of print_r(), var_dump() and die()
# The array below can be extended for further checks
# Bruno's modifications:
# - Adds some JS checkup
# - Enable checkup in more languages
# - Fix the bug on the git status command
@brunoluiz
brunoluiz / convert-to-utf-8.sh
Last active November 28, 2016 01:34
Convert Windows encoding to UTF-8 on MAC/Linux
for file in *; do
iconv -f iso-8859-1 -t utf-8 $file > $file.new
mv $file.new $file
done