Skip to content

Instantly share code, notes, and snippets.

View guilhermehn's full-sized avatar

Guilherme Nagatomo guilhermehn

  • PagSeguro
  • Brasil, São Paulo
View GitHub Profile
@guilhermehn
guilhermehn / gist:3916241
Created October 19, 2012 04:27
Javascript: Sort arrays config
function crescente (index1, index2){return index1 - index2;}
function decrescente (index1, index2){return index2 - index1;}
var ar = [2, 5, 4, 9, 1, 3, 6, 7, 8, 0];
ar.sort(crescente);
ar.sort(decrescente);
@guilhermehn
guilhermehn / gist:3916224
Created October 19, 2012 04:23
Javascript: Create Gradient
/*************************
Cross Browser Gradient Backgrounds
v1.0
Last Revision: 11.03.2005
steve@slayeroffice.com
please leave this notice in tact.
should you improve upon this code, please
@guilhermehn
guilhermehn / gist:3916199
Created October 19, 2012 04:17
Javascript: Switch stylesheets
function trocarcss(title) {
var i, a, main;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
a.disabled = true;
if(a.getAttribute("title") == title) a.disabled = false;
}
}
}
@guilhermehn
guilhermehn / gist:3916191
Created October 19, 2012 04:14
HTML+jQuery+CSS: Flip menu
<!DOCTYPE html>
<html lang="en">
<head>
<title>Flip Menu</title>
<style type="text/css">
body {
text-align: center;
background: #676767;
font-family: helvetica;
}
@guilhermehn
guilhermehn / gist:3916188
Created October 19, 2012 04:11
Javascript: addEvent
var addEvent = (function( window, document ) {
if ( document.addEventListener ) {
return function( elem, type, cb ) {
if ( elem && !elem.length ) {
elem.addEventListener(type, cb, false );
}
else if ( elem && elem.length ) {
var len = elem.length;
for ( var i = 0; i < len; i++ ) {
addEvent( elem[i], type, cb );
@guilhermehn
guilhermehn / gist:3916167
Created October 19, 2012 04:06
CSS:Leopard like button
.button {
display: inline-block;
margin: 20px;
padding: 3px 6px;
font-family: 'Lucida Grande', Arial, sans-serif;
font-size: 13px;
font-weight: semibold;
-webkit-border-radius: 3px;
@guilhermehn
guilhermehn / gist:3800167
Created September 28, 2012 14:24
CSS: Image replacement
.ir{
border:0;
font: 0/0 a;
text-shadow: none;
color: transparent;
background-color: transparent;
}
@guilhermehn
guilhermehn / gist:3800128
Created September 28, 2012 14:15
Javascript: Validar CPF
function valida_cpf(cpf) {
var numeros, digitos, soma, i, resultado, digitos_iguais;
digitos_iguais = 1;
if (cpf.length < 11) return false;
for (i = 0; i < cpf.length - 1; i++)
if (cpf.charAt(i) != cpf.charAt(i + 1)) {
digitos_iguais = 0;
break;
@guilhermehn
guilhermehn / campo-numerico.js
Created September 28, 2012 14:14
JavaScript: Campo numérico (jQuery)
$(".numerico").keypress(function(e){
var charcode = e.keyCode ? e.keyCode : e.which;
if(charcode < 48 || charcode > 57){
e.preventDefault();
return false;
}
});
@guilhermehn
guilhermehn / gist:1993257
Created March 7, 2012 13:47
Javascript: Kill hard-coded events
(function(d) {
var tags = d.body.getElementsByTagName('*');
var i = tags.length;
while (i--) {
var attr = tags[i].attributes;
var ii = attr.length;
while (ii--) {
if (attr[ii].name.match(/^on/i)) {