Skip to content

Instantly share code, notes, and snippets.

View leizongmin's full-sized avatar
😴
I may be slow to respond

LEI Zongmin leizongmin

😴
I may be slow to respond
View GitHub Profile
@leizongmin
leizongmin / toISOString.js
Created August 22, 2016 10:28
toISOString(date)
function toISOString(date) {
function pad(n) {
return n < 10 ? '0' + n : String(n);
}
return date.getFullYear() +
'-' + pad(date.getMonth() + 1) +
'-' + pad(date.getDate()) +
'T' + pad(date.getHours()) +
':' + pad(date.getMinutes()) +
':' + pad(date.getSeconds()) +
@leizongmin
leizongmin / merge.js
Created July 29, 2016 02:23
合并多个对象
function merge() {
function _merge(list) {
const obj = {};
for (const item of list) {
for (const i in item) {
obj[i] = item[i];
}
}
return obj;
}
@leizongmin
leizongmin / merge.js
Created July 29, 2016 02:23
合并多个对象
function merge() {
function _merge(list) {
const obj = {};
for (const item of list) {
for (const i in item) {
obj[i] = item[i];
}
}
return obj;
}
@leizongmin
leizongmin / TailStream.js
Last active July 24, 2016 07:00
like exec `tail -f filename` 读取文件末尾新增部分内容并输出
'use strict';
const fs = require('fs');
const stream = require('stream');
class TailStream extends stream.Readable {
/**
* TailStream
*
@leizongmin
leizongmin / png-to-ascii.js
Created December 17, 2015 08:50
将png图片转换成字符
'use strict';
const path = require('path');
const fs = require('fs');
const PNGReader = require('png.js');
function thumb(file, width, bits, callback) {
fs.readFile(file, function (err, bytes) {
@leizongmin
leizongmin / png-to-ascii.js
Created December 17, 2015 08:48
将png图片转换成字符
'use strict';
const path = require('path');
const fs = require('fs');
const PNGReader = require('png.js');
function thumb(file, width, bits, callback) {
fs.readFile(file, function (err, bytes) {
@leizongmin
leizongmin / command.bash
Created December 4, 2015 03:58
forward port to public remote host 将端口转发到远程服务器
iptables -t nat -A PREROUTING -p tcp --dport 22 -j DNAT --to XX.XX.XX.XX:22
iptables -A FORWARD -p tcp -d XX.XX.XX.XX --dport 22 -j ACCEPT
iptables -t nat -A POSTROUTING -j MASQUERADE
@leizongmin
leizongmin / lightSelector.js
Last active December 3, 2015 03:53
简单选择器
(function (global, fullName, sortName) {
function Selector(q) {
if (q instanceof Selector) return q;
if (!(this instanceof Selector)) return new Selector(q);
var list;
if (typeof q === 'string') {
list = document.querySelectorAll(q);
Selector.from(list, this);
} else if (q instanceof Element) {
function fuck1 () {
function readdir (dir) {
return ['a', 'b', 'c', 'd', 'e'].map(function (n) {
return dir + n;
}).filter(function (n) {
return n;
});
}
function addTo (obj, list) {
list.forEach(function (n) {
@leizongmin
leizongmin / comment.js
Created September 23, 2014 13:53
神注释
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// . ' \\| |// `.
// / \\||| : |||// \
// / _||||| -:- |||||- \
// | | \\\ - /// | |