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
| // pattern-prototype.js | |
| // ===== 1. use Object.create ===== | |
| var person = { | |
| nation: 'china', | |
| say: function (something) { | |
| console.log(this.name, 'says: ', something); | |
| } | |
| }; |
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
| // pattern-pubsub.js | |
| var pubsub = {}; | |
| (function (ps) { | |
| var topics = {}; // store topics | |
| var subId = -1; // identify subcribers | |
| ps.publish = function (topic, args) { | |
| var subcribers = topics[topic]; |
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 singleton = (function () { | |
| function Singleton(opts) { | |
| this.createdAt = opts.createdAt || new Date(); | |
| } | |
| var _instance; | |
| var static = { | |
| name: 'singleton', | |
| getInstance: function (opts) { |
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 scrolledIntoView = function(element) { | |
| var coords = element.getBoundingClientRect(); | |
| return ((coords.top >= 0 && coords.left >= 0 && coords.top) <= (window.innerHeight || document.documentElement.clientHeight)); | |
| }; |
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
| deleteFolderRecursive = function(path) { | |
| var files = []; | |
| if( fs.existsSync(path) ) { | |
| files = fs.readdirSync(path); | |
| files.forEach(function(file,index){ | |
| var curPath = path + "/" + file; | |
| if(fs.lstatSync(curPath).isDirectory()) { // recurse | |
| deleteFolderRecursive(curPath); | |
| } else { // delete file | |
| fs.unlinkSync(curPath); |
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 docElem = window.document.documentElement; | |
| function getViewportH() { | |
| var client = docElem['clientHeight'], | |
| inner = window['innerHeight']; | |
| if( client < inner ) | |
| return inner; | |
| else | |
| return client; | |
| } |
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
| window.requestAnimFrame = function(){ | |
| return ( | |
| window.requestAnimationFrame || | |
| window.webkitRequestAnimationFrame || | |
| window.mozRequestAnimationFrame || | |
| window.oRequestAnimationFrame || | |
| window.msRequestAnimationFrame || | |
| function(/* function */ callback){ | |
| window.setTimeout(callback, 1000 / 60); | |
| } |
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
| git config --global https.proxy http://127.0.0.1:1080 | |
| git config --global https.proxy https://127.0.0.1:1080 | |
| git config --global --unset http.proxy | |
| git config --global --unset https.proxy | |
| npm config delete proxy |
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 results = ["http://heeeeeeeey.com/", | |
| "http://cant-not-tweet-this.com/", | |
| "http://eelslap.com/", | |
| "http://www.staggeringbeauty.com/", | |
| "http://www.omfgdogs.com/", | |
| "http://burymewithmymoney.com/", | |
| "http://www.fallingfalling.com/", | |
| "http://www.a-blue-box.com/", | |
| "http://ducksarethebest.com/", | |
| "http://www.trypap.com/", |
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
| void function() { | |
| function format(template, json) { | |
| return template.replace(/#\{(.*?)\}/g, function(all, key) { | |
| return json && (key in json) ? json[key] : ""; | |
| }); | |
| } | |
| document.getElementById('panel').innerHTML = format( | |
| String(function(){/*! | |
| <ul> |
NewerOlder