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
| echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc | |
| . ~/.bashrc | |
| mkdir ~/local | |
| mkdir ~/node-latest-install | |
| cd ~/node-latest-install | |
| curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1 | |
| ./configure --prefix=~/local | |
| make install # ok, fine, this step probably takes more than 30 seconds... | |
| curl https://npmjs.org/install.sh | sh |
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
| echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc | |
| . ~/.bashrc | |
| mkdir ~/local | |
| mkdir ~/node-latest-install | |
| cd ~/node-latest-install | |
| curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1 | |
| ./configure --prefix=~/local | |
| make install # ok, fine, this step probably takes more than 30 seconds... | |
| curl https://npmjs.org/install.sh | sh |
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 speicalChar = /[^\w\s]/gi; // special characters | |
| if(speicalChar.test(str)){ | |
| // do 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
| 其他单位 秒 | |
| 1 分 60 秒 | |
| 1 小时 3600 秒 | |
| 1 天 86400 秒 | |
| 1 周 604800 秒 | |
| 1 月 (30.44 天) 2629743 秒 | |
| 1 年 (365.24 天) 31556926 秒 |
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 removeHtmlTag(str){ | |
| var reg = /(<([^>]+)>)/ig; | |
| return str.replace(reg, ""); | |
| } |
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 mobiles = []; | |
| for (var i = 0; i < 200000; i++) { | |
| mobiles[i] = (13000000000 + Math.floor(Math.random() * 1000000000)).toString(); | |
| } |
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($){ | |
| $.extend($.fn,{ | |
| pluginName: function(options){ | |
| return this.each(function(){ | |
| var pluginName = $.data(this, "pluginName"); | |
| if(!pluginName){ | |
| pluginName = new $.pluginName(options, this); | |
| $.data(this, "pluginName", pluginName); |
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
| _encodeHTML: function(source){ //转换特殊字符 | |
| return source.replace(/&/g, '&') | |
| .replace(/</g, '<') | |
| .replace(/>/g, '>') | |
| .replace(/"/g, """) | |
| .replace(/\(/g, "(") | |
| .replace(/\)/g, ")") | |
| .replace(/\$/g, "$") | |
| .replace(/'/g, "'"); | |
| } |
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
| // from http://scratch99.com/web-development/javascript/convert-bytes-to-mb-kb/ | |
| function bytesToSize(bytes) { | |
| var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; | |
| if (bytes == 0) return 'n/a'; | |
| var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); | |
| if (i == 0) return bytes + ' ' + sizes[i]; | |
| return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i]; | |
| }; |
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
| // from http://stackoverflow.com/questions/5786186/javascript-age-count-from-date-of-birth | |
| function date2Age(str){ // 根据年月日计算年龄str 格式为yyyy-mm-dd | |
| var diff = new Date - new Date(parseISO8601(str)); | |
| var diffdays = diff / 1000 / (60 * 60 * 24); | |
| return Math.floor(diffdays / 365.25) | |
| } | |
| //form http://stackoverflow.com/questions/2182246/javascript-dates-in-ie-nan-firefox-chrome-ok | |
| function parseISO8601(dateStringInRange) { // fixed IE8 NaN | |
| var isoExp = /^\s*(\d{4})-(\d\d)-(\d\d)\s*$/, | |
| date = new Date(NaN), |