Skip to content

Instantly share code, notes, and snippets.

@chemzqm
chemzqm / client.js
Created February 10, 2014 08:12
TCP server & client
var net = require ('net');
var fs = require ('fs');
var client = net.connect(3000, '127.0.0.1');
var log = fs.createWriteStream('out.log');
log.on('error', function(err) {
console.log(err);
})
// Check for the various File API support.
if (window.File && window.FileReader && window.FileList && window.Blob) {
// Great success! All the File APIs are supported.
} else {
alert('The File APIs are not fully supported in this browser.');
}
@chemzqm
chemzqm / gist:8469002
Last active January 3, 2016 13:19
点乐内嵌广告js调用后端测试代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>webview ad for testing</title>
</head>
<body>
<div id="info">info</div>
<div id="download">download</div>
@chemzqm
chemzqm / format.js
Created October 30, 2013 05:46
pretty error format for node
require('longjohn')
var prettyjson = require('prettyjson')
function formatJson(object) {
// adds 4 spaces in front of each line
var json = prettyjson.render(object)
json = json.split('\n').join('\n ')
return ' ' + json
}
function playNiceError(error) {
// remove longjohn properties that break prettyjson
@chemzqm
chemzqm / client.js
Created October 23, 2013 10:44
后端导出svg为png到前端, image.js为express路由,rasterize.js为phantomjs运行文件,client.js为前端发送请求生成png文件请求的代码
var chart = highchart(this.el, opts).highcharts();
var svg = chart.getSVG();
request
.post('/image')
.send({
xml: svg
})
.set('Accept', 'application/json')
.end(function(err, res) {
if(err) throw err;
@chemzqm
chemzqm / validate.js
Created May 19, 2013 12:54
生成验证码,保存到session
/*
* service for simple validate
*/
var express = require ('express');
var app = module.exports = express();
var Canvas = require('canvas');
var moment = require('moment');
function vertify_img(req, res) {