Skip to content

Instantly share code, notes, and snippets.

View alissonsales's full-sized avatar

Alisson Sales alissonsales

  • Wellington, New Zealand
View GitHub Profile
class Hash
def diff(hash)
raise ArgumentError, 'Argument is not a Hash' unless hash.is_a? Hash
kkeys = []
self.keys.each do |k|
diff = self[k].diff(hash[k]) if self[k].is_a? Hash and hash[k].is_a? Hash
kkeys << {k => diff} if diff and diff.size > 0
end
diff = self.keys - hash.keys
kkeys << diff if diff and diff.size > 0
/*
f = número de casas decimais
d = separador de decimos (’,’ virgula por padrão)
t = separador de milhar (’.’ ponto por padrão)
*/
String.prototype.currencyFormat = function (f, d, t) {
var n = (n = this.match(/\d/g)) ? n.join('').replace(/^0+/,'') : '0', f = (f) ? f : 2, d = (d) ? d : ',', t = (t) ? t : '.';
if (n.length < f + 1) return '0' + d + ((n.length < f) ? new Array(f - n.length + 1).join('0') + n : n)
else return n.substr(0, n.length - f).split('').reverse().join('').match(/\d{1,3}/g).join(t).split('').reverse().join('') + d + n.substr(n.length - f)