This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserValidator | |
include ActiveModel::Validations | |
def self.fields | |
[:username, :password, :email, :phone, :age] | |
end | |
attr_accessor(*fields) | |
validates :username, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validator::Factory.register(self, UserValidator) | |
validates_with Validator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if UserValidator.new(user).valid? | |
user.save | |
redirect_to user_path(user) | |
else | |
render :new | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseValidator | |
include ActiveModel::Validations | |
def initialize(record_params = {}) | |
self.class.fields.each do |field| | |
val = record_params[field] | |
send("#{field}=", val) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile | |
alias gff="git-flow feature" | |
alias be="bundle exec" | |
cd ~/projects | |
parse_git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \[\1\]/' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[alias] | |
st = status | |
ci = commit | |
co = checkout | |
di = diff | |
dc = diff --cached | |
amend = commit --amend | |
aa = add --all | |
ff = merge --ff-only | |
pullff = pull --ff-only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>Hello React!</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.1/react.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.1/react-dom.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script> | |
</head> | |
<body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// calculator.js | |
(function(root) { | |
var calculator = { | |
sum: function(a, b) { return a + b; } | |
}; | |
root.Calculator = calculator; | |
})(this); | |
// app.js | |
console.log(Calculator.sum(1, 2)); // => 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// calculator.js | |
module.exports.sum = function (a, b) { | |
return a + b; | |
}; | |
// app.js | |
var calculator = require("calculator"); | |
console.log(calculator.sum(1, 2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// calculator.js | |
define({ | |
sum: function(a, b) { | |
return a + b; | |
} | |
}); | |
// app.js | |
define(["./calculator"], function(calculator) { | |
console.log(calculator.sum(1, 2)); |