Skip to content

Instantly share code, notes, and snippets.

View rafaellyra's full-sized avatar
🎯
Focusing

Rafael Lyra rafaellyra

🎯
Focusing
  • Amsterdam
View GitHub Profile
@rafaellyra
rafaellyra / gist:6971352
Created October 14, 2013 05:53
Resolve Jekyll utf-8 error.
export LC_CTYPE=en_US.UTF-8
export LANG=en_US.UTF-8
@rafaellyra
rafaellyra / validator.regex.js
Created March 17, 2013 09:21
Adiciona methodo para validação por regex no plugin jQuery Validate.
$.validator.addMethod('regex', function (value, element, regexp) {
var check = false,
re = new RegExp(regexp);
return this.optional(element) || re.test(value);
}, 'Favor verificar os valores digitados.');
/*
Exemplo de uso :
rules: {
@rafaellyra
rafaellyra / calculatedistance.js
Created March 17, 2013 09:11
Calcula a distancia em raio entre duas coordenadas de latitude/longitude.
function CalcRadiusDistance(lat1, lon1, lat2, lon2) {
var RADIUSMILES = 3961,
RADIUSKILOMETERS = 6373,
latR1 = this.deg2rad(lat1),
lonR1 = this.deg2rad(lon1),
latR2 = this.deg2rad(lat2),
lonR2 = this.deg2rad(lon2),
latDifference = latR2 - latR1,
lonDifference = lonR2 - lonR1,
a = Math.pow(Math.sin(latDifference / 2), 2) + Math.cos(latR1) * Math.cos(latR2) * Math.pow(Math.sin(lonDifference / 2), 2),
@rafaellyra
rafaellyra / trim.js
Created March 17, 2013 09:05
Extensão do trim() para navegadores que não possuem esse método javascript nativo.
if (typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
}
}
@rafaellyra
rafaellyra / clonenode.js
Created December 13, 2012 02:55
How to clone a dom element using native javascript I needed to clone a dom element in a project and have searched this at google and stackoverflow but i just finded a lot of big functions to do this, looking at jsref I findend the cloneNode method, a native javascript method to clone dom elements.
//Syntax
var dupNode = node.cloneNode(deep);
/*
node -> The node to be cloned.
dupNode -> The new node that will be a clone of node
deep (Optional) ->
[true] if the children of the node should also be cloned, or [
false] to clone only the specified node.