Skip to content

Instantly share code, notes, and snippets.

View dongyuwei's full-sized avatar
💭
天天听儿歌

dongyuwei dongyuwei

💭
天天听儿歌
View GitHub Profile
@dongyuwei
dongyuwei / spawn_svn.js
Created April 19, 2012 06:48
nodejs spawn svn cmd ,chunked putput to broswer ; 在浏览器上实时查看svn命令输出
var express = require('express'), spawn = require('child_process').spawn;
var util = require('util');
var app = express.createServer();
app.use(app.router);
var svn;
app.get('/svn', function(req, res) {
res.writeHead(200, {
'Content-Type': 'text/html;charset=utf-8'
@dongyuwei
dongyuwei / starredFeed.js
Created May 25, 2012 07:24
打印出最近100条加星标的google reader feed.
/*
This library was developed by Will Honey.
It is licensed under the GPLv3 Open Source License
This library requires the underscore library found at http://documentcloud.github.com/underscore/
This library requires the underscore string library found at http://edtsech.github.com/underscore.string/
This library requires the support of localStorage. Updates could be easily made to change that.
*/
@dongyuwei
dongyuwei / cssFilter.js
Created May 28, 2012 07:20
filter css rule(去掉前面相同的规则,保留最后那条规则)
/**
* filter css rule(去掉前面相同的规则,保留最后那条规则)
* */
module.exports = function(css, filePath) {
var list = [], index;
css.split(/\}/g).forEach(function(rule) {
rule = rule.trim();
if(rule !== '') {
rule = rule + '}';
index = list.indexOf(rule);
@dongyuwei
dongyuwei / master.js
Created June 5, 2012 02:16
TypeError: Object #<EventEmitter> has no method 'send' at queryMaster (cluster.js:215:11) at EventEmitter._startWorker (cluster.js:184:3) at startup (node.js:91:17) at node.js:551:3
var cluster = require('cluster');
var childProcess = require('child_process');
var path = require('path');
if(cluster.isMaster) {
childProcess.fork(path.join(__dirname,'worker.js'));
} else {
//do nothing
}
@dongyuwei
dongyuwei / test-spdy.js
Created June 27, 2012 09:36
test-spdy
var spdy = require('spdy'), fs = require('fs');
var options = {
key : fs.readFileSync(__dirname + '/keys/spdy-key.pem'),
cert : fs.readFileSync(__dirname + '/keys/spdy-cert.pem'),
ca : fs.readFileSync(__dirname + '/keys/spdy-csr.pem')
};
var server = spdy.createServer(options, function(req, res) {
res.writeHead(200, {
@dongyuwei
dongyuwei / path.existsSync.js
Created June 28, 2012 08:38
path.existsSync change to fs.existsSync
var fs = require('fs'), path = require('path');
path.existsSync = fs.existsSync ? function(uri){return fs.existsSync.call(fs,uri)} : path.existsSync;
@dongyuwei
dongyuwei / mkdirP.js
Created July 12, 2012 04:17
mkdir -p in nodejs
var fs = require('fs'), path = require('path');
var pDir = '';
function mkdriP(uri,mode) {
if(uri === '') {//递归结束
pDir = null;
return ;
}
var list = uri.split(path.sep);
pDir = path.join(path.sep, pDir, list.shift());
@dongyuwei
dongyuwei / weibo-oauth2.js
Created July 27, 2012 10:19
sina weibo oauth2 api,in nodejs
var https = require('https');
var path = require('path');
var fs = require('fs');
var qs = require('querystring');
var express = require('express');
var multiparter = require("multiparter");
process.on('uncaughtException', function(err) {
console.error('Caught exception: ', err);
});
@dongyuwei
dongyuwei / weibo_wap.js
Created August 14, 2012 07:45
自动登陆新浪微博移动版( http://m.weibo.cn ) 发微博
var http = require('http');
var qs = require('querystring');
function parse_response(res, callback) {
var list = [];
res.on('data', function(chunk) {
list.push(chunk);
});
res.on('end', function() {
callback(Buffer.concat(list).toString());
@dongyuwei
dongyuwei / replace-img-src.js
Created August 29, 2012 08:24
批量把所有img `src`属性改成`data-src`属性(及其值)
var fs = require('fs');
var path = require('path');
var html = fs.readFileSync(path.join(__dirname,'./img-original.html'),'utf-8');
var htmlLazy = html.replace(/\s+src="(.+?)"/ig,function(){
var m = RegExp.$1;
if(m.match(/[\.png|\.jpg|\.jpeg|\.gif]$/)){
return ' data-src="' + m +'" ' ;
}else{