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 pad(len, num) { | |
| return (new Array(len + 1).join('0') + num).slice(-len); | |
| } | |
| pad(2, 1); // 01 | |
| pad(2, 11); // 11 | |
| pad(10, 12345); // 0000012345 | |
| pad(10, 12345678); // 0012345678 | |
| pad(10, 1234567890); // 1234567890 |
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
| /** | |
| * @author zhixin wen <[email protected]> | |
| * @version 0.0.1 | |
| * @github https://github.com/wenzhixin/ | |
| * @blog http://wenzhixin.net.cn | |
| */ | |
| (function($) { | |
| 'use strict'; |
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 getSize(value) { | |
| var b1 = Math.pow(2, 10), //KB | |
| b2 = Math.pow(2, 20), //MB | |
| b3 = Math.pow(2, 30), //GB | |
| b4 = Math.pow(2, 40), //TB | |
| value = value.toLowerCase(), | |
| size = parseFloat(value); | |
| if (!size) { | |
| return 0; |
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 parse(search) { | |
| var query = {}, | |
| params = search.substring(1).split('&'); | |
| for (var i = 0, l = params.length; i < l; i++) { | |
| var p = params[i].split('='); | |
| query[p[0]] = p[1] || ''; | |
| } | |
| return query; | |
| } |
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 u = url('http://wenzhixin.net.cn:12345/test?name=wenzhixin#about'); | |
| * console.log(u.protocol); // http: | |
| * console.log(u.hostname); // wenzhixin.net.cn | |
| * console.log(u.port); // 12345 | |
| * console.log(u.pathname); // /test | |
| * console.log(u.search); // ?name=wenzhixin | |
| * console.log(u.hash); // #about | |
| */ | |
| function url(href) { |
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 timer(func, start, interval, end) { | |
| start = start || 0; | |
| if (arguments.length <= 2) { | |
| setTimeout(func, start); | |
| } else { | |
| var repeat = function() { | |
| var i = setInterval(func, interval); | |
| end && setTimeout(function() { | |
| clearInterval(i); | |
| }, end); |
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 fs = require('fs'), | |
| MongoClient = require('mongodb').MongoClient, | |
| Server = require('mongodb').Server, | |
| options = null; | |
| mongoClient = null; | |
| if (process.argv.length <= 2 || process.argv.indexOf('--help') !== -1) { | |
| showHelp(); | |
| return; |
NewerOlder