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
| function typeOf(o) { | |
| var type = (o === null) ? 'null' : typeof o; | |
| return (type == 'object') ? Object.prototype.toString.call(o).slice(8, -1).toLowerCase() : type; | |
| } | |
| //Example: typeOf(new Date()) => 'date' |
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
| RegExp.escape = function(str) { | |
| return str.replace(/[-\\^$*+?.()|[\]{}]/g, "\\$&"); | |
| } | |
| //Example: string.replace(new RegExp(RegExp.escape('a&b'), 'g'), 'c&d') | |
| //Credit: http://simonwillison.net/2006/Jan/20/escape/#p-6 |
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
| function formatNumber(val) { | |
| return String(val).replace(/\B(?=(\d{3})+(?!\d))/g, ','); | |
| } | |
| //formatNumber('1000000') => '1,000,000' |
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
| (function(exports) { | |
| "use strict"; | |
| //elements containing un-escaped contents | |
| var CDATA = {"script": 1, "style": 1}; | |
| //"void" elements that must not have content or an end tag (self-closing in XHTML) | |
| var EMPTY = {"area": 1, "base": 1, "br": 1, "col": 1, "hr": 1, "img": 1, "input": 1, "link": 1, "meta": 1, "param": 1, "wbr": 1}; | |
| //manually generate an element's innerHTML with lowercase identifiers | |
| function getInnerHtml(el) { |
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> | |
| <meta http-equiv="Cache-Control" content="private, no-cache, proxy-revalidate" /> | |
| <meta http-equiv="Refresh" content="0;url=http://example.com/path" /> | |
| <title>Redirecting...</title> | |
| </head> | |
| <body onload="location.replace(document.getElementsByTagName('meta')[1].content.slice(6))"> | |
| <noscript><p>Redirecting...</p></noscript> | |
| </body> |
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 construct = (function() { | |
| var Fn = function() {}; | |
| var create = Object.create || function(obj) { | |
| Fn.prototype = obj; | |
| return new Fn(); | |
| }; | |
| return function construct(ctor, args) { | |
| var instance = create(ctor.prototype); | |
| var result = ctor.apply(instance, args); | |
| return (Object(result) === result) ? result : instance; |
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
| function isEql(a, b) { | |
| if (keys(a).sort().join() !== keys(b).sort().join()) { | |
| return false; | |
| } | |
| for (var key in a) { | |
| if (a[key] !== b[key]) return false; | |
| } | |
| return true; | |
| } |
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
| node -e "console.log(require('fs').readFileSync('path/to/image.png').toString('base64'))" |
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 o = queryParams.split('&').reduce(function(o, el) { var a = el.split('='); o[decodeURIComponent(a[0])] = decodeURIComponent(a[1] || ''); return o }, {}); | |
| // (Not completely safe, because it will throw for invalid UTF-8 sequences) | |
| // Note: Use queryParams.slice(1) if queryParams starts with ? as in location.search |
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
| (function() { | |
| "use strict"; | |
| var RE_COMMENT = /<!--(.*?)-->/g; | |
| var RE_SCRIPT = /<script[\s>](.*?)<\/script\s*>/ig; | |
| //simple regex-based cleaning to strip scripts and comments | |
| function htmlClean(html) { | |
| var last, clean = (html == null) ? '' : String(html); | |
| //repeatedly clean markup until cleaning has no more effect |
OlderNewer