// Do not use document.write, use DOM access instead
$( '#element' ).append(' <div>text</div>' );
// Incorrect
document.write('<div>text</div>');
// Use feature detection, not browser/User-Agent sniffing
if ( document.addEventListener ) {
This file contains hidden or 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
person.eat(food, function() { | |
if (typeof food === 'tacobell') { | |
// Kinda yum... | |
setInterval(function() { | |
// Oh noes! | |
// http://www.hulu.com/watch/10304/saturday-night-live-colon-blow | |
colon.blow(); | |
}, 120000); // 2 hrs. | |
} | |
}); |
This file contains hidden or 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
// JSLint: | |
/*global window, parseInt*/ | |
// Conditionally check value, in case | |
// future implementations of parseInt | |
// provide native base-10 by default. | |
(function () { | |
var _parseInt = window.parseInt; | |
if (_parseInt('09') === 0) { |
This file contains hidden or 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></head> | |
<body> | |
<ul> | |
<li><a href="#">1</a></li> | |
<li><a href="#">2</a></li> | |
<li><a href="#">3</a></li> | |
</ul> |
This file contains hidden or 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
define(function () { | |
var HttpError = function (msg, code) { | |
var ex = new Error(msg || 'Unknown HTTP error'); | |
ex.code = code; | |
ex.toString = function() { | |
return 'Error: ' | |
+ (this.code ? '' : '(' + this.code + ') ') | |
+ this.message; | |
}; |
This file contains hidden or 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
var css = 'insert lots of css here'; | |
var files = {}; | |
css = css.replace(/url\((\S*)\.(png|jpg|jpeg|gif)\)/g, function(match, file, type) | |
{ | |
var fileName = file + '.' + type; | |
var base64 = fs.readFileSync(fileName).toString('base64'); | |
if (typeof(files[fileName]) !== 'undefined') { | |
console.log('Warning: ' + fileName + ' has already been base64 encoded in the css'); | |
} |
This file contains hidden or 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 lang="en"> | |
<head> | |
<title>jQuery Deferreds and Promises</title> | |
</head> | |
<body> | |
<div class="container"> | |
<form method="get" action="http://search.twitter.com/search.json"> | |
<input type="search" class="search"> | |
<input type="submit" value="Search teh Tweets!" class="submit"> |
This file contains hidden or 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
DO WHAT THE **** YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 Eli Perelman <http://eliperelman.com> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE **** YOU WANT TO PUBLIC LICENSE |
This file contains hidden or 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
var App = (function() { | |
var module1 = { | |
method1: function() { | |
// code here | |
} | |
}; | |
var module2 = { | |
ajax: $.ajax |
This file contains hidden or 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
var Namespace = {}; | |
Namespace.module1 = { | |
method1: function() { | |
// code here | |
} | |
}; | |
Namespace.module2 = { | |
method2: function() { |