Skip to content

Instantly share code, notes, and snippets.

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

dongyuwei dongyuwei

💭
天天听儿歌
View GitHub Profile
@dongyuwei
dongyuwei / SimpleCluster.js
Created January 31, 2012 01:56 — forked from wankdanker/SimpleCluster.js
A simple cluster module that re-spawns child processes that have died. Also reloads child processes when `require()`d script files have changed.
/*jslint node: true, maxerr: 50, indent: 4 */
"use strict";
var clusterInstance;
var SimpleCluster = module.exports = function () {
//there should only be one instance of this per process
if (clusterInstance) {
return clusterInstance;
@dongyuwei
dongyuwei / xmpp_robot4weibo.rb
Created February 2, 2012 03:01
xmpp robot for weibo 微博XMPP私信机器人
require 'rubygems'
require 'eventmachine'
require 'xmpp4r-simple'
jabber = Jabber::Simple.new("[email protected]", "password_of_weibo")
#at_exit{jabber.status(:away, "jabot down")}
EM.run do
EM::PeriodicTimer.new(1) do
jabber.received_messages do |message|
case message.body
@dongyuwei
dongyuwei / pg.1.java
Created February 20, 2012 14:57
phonegap
/**
* Tell the client to display a prompt dialog to the user.
* If the client returns true, WebView will assume that the client will
* handle the prompt dialog and call the appropriate JsPromptResult method.
*
* Since we are hacking prompts for our own purposes, we should not be using them for
* this purpose, perhaps we should hack console.log to do this instead!
*
* @param view
* @param url
@dongyuwei
dongyuwei / node-reader.js
Created March 14, 2012 04:58
google reader api for nodejs
/*
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.
*/
/* jslint adsafe: false, devel: true, regexp: true, browser: true, vars: true, nomen: true, maxerr: 50, indent: 4 */
@dongyuwei
dongyuwei / contextMenusInTiDesktop.html
Created March 21, 2012 05:22 — forked from dawsontoth/contextMenusInTiDesktop.html
Context menus in Titanium Desktop, a quick sample.
<html>
<body>
<style type="text/css">
body {
-webkit-user-select: auto !important;
}
</style>
Here is some text.
<br />
<textarea rows="10" cols="70">
@dongyuwei
dongyuwei / proxy.js
Created March 27, 2012 10:10
http proxy for nodejs
(function(module) {
var http = require('http');
module.exports = function (request, response, serverHost, serverPort) {
response.header('X-Proxyed-By' ,'Weibo-Packager');
serverPort = serverPort || 80;
var proxyRequest = http.request({
host : serverHost || request.headers.host,
port : serverPort,
path : request.url,
method : request.method,
@dongyuwei
dongyuwei / dir2tree.js
Created March 30, 2012 07:31
dir to tree by nodejs 递归遍历目录,生成一个js树对象.
(function() {
var path = require('path'), fs = require('fs');
function walk(uri,filter,tree) {
var node = {
name : null,
children : [],
pNode : null,
};
@dongyuwei
dongyuwei / cmd.js
Created April 13, 2012 02:32
nodejs system cmd
var express = require('express'), exec = require('child_process').exec;
var app = express.createServer();
app.use(app.router);
app.get('/ls', function(req, res) {
exec('ls . ', function(error, stdout, stderr) {
console.log(stdout);
res.write(stdout, 'utf-8');
res.write(stderr, 'utf-8');
if(error) {
@dongyuwei
dongyuwei / sinatra_stream.rb
Created April 13, 2012 04:09
sinatra stream
require 'rubygems'
require 'sinatra'
require 'eventmachine'
get '/evented' do
stream(:keep_open) do |out|
EventMachine::PeriodicTimer.new(1) { out << "#{Time.now}\n" }
end
end
@dongyuwei
dongyuwei / node-tail-f.js
Created April 13, 2012 04:31
nodejs stream tail -f to web browser
var express = require('express'), spawn = require('child_process').spawn;
var app = express.createServer();
app.use(app.router);
var tail;
app.get('/tail', function(req, res) {
res.header('Content-Type','text/html;charset=utf-8');
tail = spawn('tail', ['-f', './test.log']);