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
// example findFirst('a = b(1, {}, 2)', ['(', '{']) => 5 | |
function findFirst(source, list, pos) { | |
var found = -1; | |
for (var i = 0, len = list.length; i < len; i++) { | |
var index = source.indexOf(list[i], pos); | |
if (index >= 0) { | |
if (found < 0 || index < found) found = index; | |
} | |
} | |
return found; |
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 clone(obj) { | |
if (Object(obj) !== obj) return obj; | |
if (typeof obj.toJSON == 'function') { | |
return obj.toJSON(); | |
} | |
var type = toString.call(obj).slice(8, -1); | |
if (type in CLONE) { | |
return CLONE[type].call(obj, clone); | |
} | |
var copy = {}; |
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
eval = (function(eval) { return function(code) { return eval(code) } })(eval); | |
try { | |
throw null | |
} catch(app) { | |
app = function() { console.log('Hello World') } | |
app.version = '1.2'; | |
//... all my code here ... | |
//now all my code has access to app, but eval doesn't | |
//and my code can execute in global scope (if desired) | |
console.log(eval('typeof app')) |
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 toJSON(node) { | |
let propFix = { for: 'htmlFor', class: 'className' }; | |
let specialGetters = { | |
style: (node) => node.style.cssText, | |
}; | |
let attrDefaultValues = { style: '' }; | |
let obj = { | |
nodeType: node.nodeType, | |
}; | |
if (node.tagName) { |
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 mysql_escape_string(str) { | |
return str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function(ch) { | |
switch (ch) { | |
case "\0": | |
return "\\0"; | |
case "\x08": | |
return "\\b"; | |
case "\x09": | |
return "\\t"; | |
case "\x1a": |
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
//typeof replacement one-liner | |
var type = (val === null) ? 'null' : Array.isArray(val) ? 'array' : typeof val; |
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
/*! | |
* HTML Parser | |
* Ported from CKEditor 4.2 (f74e558351) | |
* | |
*/ | |
/*global require, exports, module, define */ | |
var HTMLParser; | |
(function(definition) { | |
if (typeof exports == 'object' && typeof module == 'object') { | |
// CommonJS/Node |
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 addEvent(element, eventName, callback) { | |
if (element.addEventListener) { | |
element.addEventListener(eventName, callback, false) | |
} else { | |
element.attachEvent(eventName, callback, false); | |
} | |
} |
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 img = new Image(); | |
img.onload = img.onerror = function() { | |
if (img.width != 1 || img.height != 1) { | |
document.documentElement.className += " no-data-uri"; | |
} | |
}; | |
img.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="; |
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
//Usage: Model.extend = extend; MyModel = Model.extend({some: method}) | |
function extend(protoProps, classProps) { | |
var args = Array.prototype.slice.call(arguments); | |
var ParentClass = (typeof this == 'function') ? this : args.shift(); | |
function ChildClass() { | |
var result = ParentClass.apply(this, arguments); | |
return (Object(result) === result) ? result : this; | |
} | |
ChildClass.prototype = Object.create(ParentClass.prototype, { | |
constructor: { |