This file contains 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
function f(N) { | |
return Array.apply(null, {length: N}).map(Number.call, Number); | |
} |
This file contains 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
String.prototype.replacer = function() { | |
var args = arguments | |
return this.replace(/\{([0-9]*)\}/g, function(match, parameter) { | |
return args[parseInt(parameter)] | |
}) | |
} | |
var hello = "Hello {0} {1}!" | |
hello.replacer("John", "Doe") // "Hi John Doe!" |
This file contains 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> | |
<script type="text/javascript" src="vcard2.js"></script> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
// With helper methods | |
var fooBar = vCard.create(vCard.Version.FOUR) | |
fooBar.addFormattedname("Mr Foo Bar") |
This file contains 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> | |
<script type="text/javascript"> | |
var languages = [ // source: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html | |
['Feb 2014', 'Feb 2013', 'Programming Language', 'Ratings', 'Change'], | |
[1, 2, 'C', '18.334%', '+1.25%'], | |
[2, 1, 'Java', '17.316%', '-1.07%'], | |
[3, 3, 'Objective-C', '11.341%', '+1.54%'], | |
[4, 4, 'C++', '6.892%', '-1.87%'], |
This file contains 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
function Generator() { | |
var ac = arguments.callee | |
return !ac.c && (ac.c = 0) || ac.c++ | |
} |
This file contains 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> | |
<meta content="img-src https://github.com/login;" http-equiv="Content-Security-Policy"> | |
<script type="text/javascript"> | |
var islogged = true | |
window.onload = function() { console.log("Logged in to Github : " + islogged) } | |
</script> |
This file contains 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> | |
<meta content="script-src 'self';" http-equiv="Content-Security-Policy"> | |
<script type="text/javascript" src="csp.js"></script> | |
</head> | |
</html> |
This file contains 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
function serialize(obj) { | |
return JSON.stringify(obj, function (key, value) { | |
return typeof value === 'function' ? value.toString() : value; | |
}) | |
} | |
function deserialize(str) { | |
return JSON.parse(str, function (key, value) { | |
if (value && typeof value === "string" && value.substr(0,8) == "function") { | |
var body = value.substring(value.indexOf('{') + 1, value.lastIndexOf('}')) |
This file contains 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 config = (function() { | |
var s = document.getElementsByTagName('script'); | |
var uri = Array.prototype.slice.call(s).slice(-1)[0].src.match(/\?.*/g) | |
return uri.length > 0 ? JSON.parse('{"' + decodeURI(uri[0].substr(1)).replace(/"/g, '\\"').replace(/&/g, '","').replace(/\=/g,'":"') + '"}') : {} | |
})() | |
/* | |
<script type="text/javascript" src="script.js?foo=bar"></script> | |
This file contains 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 blob = new Blob(["some code"], {"type": "application/javascript"}); | |
var script = document.createElement('script'); | |
script.src = URL.createObjectURL(blob); | |
document.body.appendChild(script); |