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 stack1 = []; | |
| var stack2 = []; | |
| function isEmptyStack(stack) { | |
| return stack.length === 0; | |
| } | |
| function enqueue(obj) { | |
| return stack1.push(obj); | |
| } |
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
| /** | |
| * A cross-browser custom event module. | |
| */ | |
| var global = window; | |
| var NativeCustomEvent = window.CustomEvent; | |
| function isCustomEvent() { | |
| try { | |
| var p = new NativeCustomEvent('cat', { detail: { foo: 'bar' } }); |
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
| /** | |
| * A simple cross browser input event. | |
| */ | |
| function input(node, callback) { | |
| var doc = document; | |
| var isIE9 = doc.documentMode && (doc.documentMode === 9); | |
| var isInputSupported = ('oninput' in node) && !isIE9; | |
| var inputValue = node.value; |
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 data = ["ActionScript", "C", "C#", "C++", "Clojure", "CoffeeScript", "CSS", "Go", "Haskell", "HTML", "Java", "JavaScript", "Lua", "Matlab", "Objective-C", "Perl", "PHP", "Python", "R", "Ruby", "Scala", "Shell", "Swift", "TeX", "VimL", "ABAP", "Ada", "Agda", "AGS Script", "Alloy", "AMPL", "Ant Build System", "ANTLR", "ApacheConf", "Apex", "API Blueprint", "APL", "AppleScript", "Arc", "Arduino", "AsciiDoc", "ASP", "AspectJ", "Assembly", "ATS", "Augeas", "AutoHotkey", "AutoIt", "Awk", "Batchfile", "Befunge", "Bison", "BitBake", "BlitzBasic", "BlitzMax", "Bluespec", "Boo", "Brainfuck", "Brightscript", "Bro", "C-ObjDump", "C2hs Haskell", "Cap'n Proto", "CartoCSS", "Ceylon", "Chapel", "ChucK", "Cirru", "Clarion", "Clean", "CLIPS", "CMake", "COBOL", "ColdFusion", "ColdFusion CFC", "Common Lisp", "Component Pascal", "Cool", "Coq", "Cpp-ObjDump", "Creole", "Crystal", "Cucumber", "Cuda", "Cycript", "Cython", "D", "D-ObjDump", "Darcs Patch", "Dart", "desktop", "Diff", "DIGITAL Command Language", "DM", "Dockerfile", |
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
| /** | |
| * Unix timestamp - The number of seconds that have elapsed since 1970-01-01 00:00:00 UTC. | |
| */ | |
| function timestamp() { | |
| return Math.round((Date.now ? Date.now() : new Date()) / 1000); | |
| } |
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
| /** | |
| * switch vs object | |
| */ | |
| var dateMethods = { | |
| Y: 'FullYear', | |
| M: 'Month', | |
| D: 'Date', | |
| h: 'Hours', | |
| m: 'Minutes', |
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
| /** | |
| * Common regular expressions | |
| */ | |
| var rules = { | |
| alphabet: /^[a-zA-Z]+$/, | |
| numeric: /^[0-9]+$/, | |
| alphanumeric: /^[0-9a-zA-Z]+$/, | |
| alphadash: /^[0-9a-zA-Z_]+$/, | |
| ascii: /[\x00-\xff]/, | |
| nonascii: /[^\x00-\xff]/ |
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
| /** | |
| * A simple string template function. | |
| * | |
| * For example: | |
| * | |
| * var str = 'Hi, {{ username }}! Your age is {{ age }}. You locate in {{ location.city }}, {{ location.province }}.'; | |
| * var user = { | |
| * username: 'Alex Chao', | |
| * age: 25, | |
| * location: { |
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
| /** | |
| * Pick N elements from an array randomly. | |
| */ | |
| function randPick(arr, n) { | |
| var len = arr.length; | |
| var randIdx; | |
| var tmp; | |
| while (n--) { |
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
| /** | |
| * Escape regexp special characters. The slash `/` will be escaped automatically. | |
| * http://stackoverflow.com/questions/494035/how-do-you-pass-a-variable-to-a-regular-expression-javascript/494122#494122 | |
| */ | |
| function escapeRegexp(str) { | |
| return str.replace(/[.*+?^$|[\](){}\\-]/g, '\\$&'); | |
| } |