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:1992714
Created March 7, 2012 11:56
Javascript: Detect IE
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@guilhermehn
guilhermehn / gist:1992731
Created March 7, 2012 12:01
CSS: Image Replacement
.ir {
border:0;
font: 0/0 a;
text-shadow: none;
color: transparent;
background-color: transparent;
}
@guilhermehn
guilhermehn / gist:1992732
Created March 7, 2012 12:01
HTML: Prompt Chrome Frame
<!-- Prompt IE6 users to install Chrome Frame -->
<!--[if lt IE 7 ]>
<script src="//ajax.googleapis.com/ajax/libs/chrome-frame/1.0.3/CFInstall.min.js"></script>
<script>window.attachEvent('onload',function(){CFInstall.check({mode:'overlay'})})</script>
<![endif]-->
@guilhermehn
guilhermehn / gist:1992760
Created March 7, 2012 12:10 — forked from zetareticoli/gist:934071
CSS: Micro clearfix
/* For modern browsers */
.cf:before,
.cf:after {
content:"";
display:block;
}
.cf:after {
clear:both;
}
@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)) {
@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: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 / 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: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: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 );