Skip to content

Instantly share code, notes, and snippets.

@dllmoe
dllmoe / go.js
Created July 27, 2017 06:47
异步
function go(func){
let gen = func()
function next(data){
if(!data.done) data.value.next(dt => next(gen.next(dt)))
}
return next(gen.next())
}
@dllmoe
dllmoe / static-server.js
Created July 1, 2017 11:11
静态服务器
const http = require('http');
const fs = require('fs');
const parseUrl = require('url').parse;
const extname = require('path').extname;
const joinPath = require('path').join;
const Mimes = {
".html": "text/html",
".css": "text/css",
".js": "application/x-javascript",
function ttkUpload(file, token, cb){
// file = input[type=file]
var url = "http://up.imgapi.com/";
var fd = new FormData(), xhr = new XMLHttpRequest();
var f = file.files[0];
fd.append('file', f);
fd.append('Token', token);
xhr.open("POST", url, true);
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200){
var tty = require('tty');
var styles = {
'bold': ['\033[1m', '\033[22m'],
'italic': ['\033[3m', '\033[23m'],
'underline': ['\033[4m', '\033[24m'],
'inverse': ['\033[7m', '\033[27m'],
'black': ['\033[30m', '\033[39m'],
'red': ['\033[31m', '\033[39m'],
'green': ['\033[32m', '\033[39m'],
@dllmoe
dllmoe / ip2dec.js
Created October 8, 2016 03:32
ip地址转十进制
#!/usr/bin/nodejs
function showHelp(){
console.log('Usage: ipnum [ip] ...');
}
function convert(ip){
if(typeof ip !== 'string') return false;
if(!/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(ip)) return false;