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 text = 'Text'; | |
var split = [' ', ' ', ' ', ' ', '\n']; | |
var i = 0; | |
for (var c = 30; c <= 39; c++) { | |
for (var bg = 40; bg <= 49; bg++) { | |
[1,2,4,5,7,22,24,25,27].forEach(function (s) { | |
var v = [c, bg, s].join(';'); | |
var sp = split[i++]; | |
if (i >= split.length) i = 0; | |
process.stdout.write(v + ' \x1B[' + v + 'm' + text + '\x1B[39;49m' + sp); |
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
/** | |
* 简单的HTTP代理服务器 | |
* | |
* @author 老雷<leizongmin@gmail.com> | |
*/ | |
var http = require('http'); | |
// 记录日志 | |
var log = function () { | |
var now = new Date().toISOString(); |
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 toZhNumber (num) { | |
num = Number(num); | |
if (isNaN(num)) return '不是数字'; | |
var numStr = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']; | |
// 正负号 | |
if (num < 0) { |
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 stream = process.stdout; | |
// 输出 | |
var write = function (str) { | |
stream.write(str); | |
}; | |
// 生成ANSI escape sequences代码:http://en.wikipedia.org/wiki/ANSI_escape_code | |
var CSI = exports.CSI = function (str, c) { |
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
// 一个特殊的国家忌讳7这个数字,所有包含7的数字他们都不用, | |
// 改用下一个数字,比如7他们用8代替,17用19代替。 | |
// 给定这个国家的数字,如何编程翻译成我们用的数字。 | |
function convert (n) { | |
// 先转成9进制,然后将大于6的数字都加1 | |
var x = n.toString(9); | |
var r = ''; | |
for (var i = 0; i < x.length; i++) { | |
if (x[i] > 6) { | |
r += parseInt(x[i]) + 1; |
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
/** | |
* 取子字符串的索引位置(不在引号内的) | |
* | |
* @param {String} text | |
* @param {String} subject | |
* @param {Integer} start | |
*/ | |
var textIndexOf = function (text, subject, start) { | |
if (start < 0) { | |
start = text.length + start; |
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
/** | |
* 返回安全的JSON字符串 | |
* | |
* @param {Object} data | |
* @param {String|Number} space 缩进 | |
* @return {String} | |
*/ | |
var jsonStringify = function (data, space) { | |
var seen = []; | |
return JSON.stringify(data, function (key, 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
/** | |
* 克隆对象 | |
* | |
* @param {Object} obj | |
* @return {Object} | |
*/ | |
var clone = function (obj) { | |
var seen = []; | |
var cloneObj = function (obj) { | |
if (typeof(obj) === 'object') { |
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 path = require('path'); | |
var fs = require('fs'); | |
var _ = require('bright-flow'); | |
// 要列出的目录 | |
var dir = path.resolve(process.argv[2]); |
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
.固定水平居中 { | |
position: fixed; | |
width: 200px; | |
left: 50%; | |
margin-left: -100px; | |
} |