Skip to content

Instantly share code, notes, and snippets.

:atom:
Coding at yuque.com

fengmk2 fengmk2

:atom:
Coding at yuque.com
Block or report user

Report or block fengmk2

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:944470
// index.js
dot.templateSettings.begin = '<?js';
dot.templateSettings.end = '?>';
// index.html
<p>hello <?js! word ?></p>
View callback-vs-event
/**
* 显示指定用户 profile 页面
*
* 获取关注和被关注的数据
* 获取此用户最近的活动数据
* - 活动数据里面包含各种数据的聚合
* 判断当前登录的用户与指定用户是否已经相互关注
*
*/
View gist:1094252
------------- new Buffer 0
free 139.82421875MB
------------- after new 1MB buffer
free 138.890625MB
------------- new Buffer 1
free 138.890625MB
------------- after new 1MB buffer
free 138.890625MB
@fengmk2
fengmk2 / mongoskin.insert.js
Created Aug 18, 2011
mongoskin unique index insert no error
View mongoskin.insert.js
var db = require('mongoskin').db('localhost:27017/taohistorytest');
db.bind('histories');
db.histories.ensureIndex('num_iid', true, function() {console.log(arguments);});
db.histories.find().toArray(function(err, items){
console.log(arguments);
});
db.histories.insert({num_iid: 1, title: 'test title'}, function() {
console.log(arguments);
});
@fengmk2
fengmk2 / gist:1185729
Created Sep 1, 2011
delete doc's child doc
View gist:1185729
{
user: shiba,
item: {
2222 : "dfdfdfdf",
3333 : "dfdfdff",
1111 : "kdkdfdfdf"
},
user: liulei,
item: {
View mongoskin-demo.js
var mongo = require('mongoskin');
var db = mongo.db('127.0.0.1:27017/test');
// create index:
// key, unique, callback
db.collection('user').ensureIndex([['name', 1]], true, function(err, replies){});
// bind method: db.user ===> db.collection('user')
db.bind('user');
View gist:1301674
> var b = new Buffer(2)
> b
<Buffer 00 00>
> b[0] = 0xcb
203
> b
<Buffer cb 00>
> b[1] = 0xd5
213
> b
@fengmk2
fengmk2 / foo.js
Created Dec 27, 2011
Find bug in code
View foo.js
Foo.prototype.get = function(key, callback) {
db.get(key, function(err, data) {
if (err) return callback(err);
try {
callback(null, JSON.parse(data.toString());
} catch(e) {
callback(e);
}
});
};
@fengmk2
fengmk2 / foo.js
Created Dec 27, 2011
Find bug in code
View foo.js
Foo.prototype.get = function(key, callback) {
db.get(key, function(err, data) {
if (err) return callback(err);
try {
callback(null, JSON.parse(data.toString()));
} catch(e) {
callback(e);
}
});
};
@fengmk2
fengmk2 / gist:1841880
Created Feb 16, 2012
one redis client demo
View gist:1841880
var redis_host='10.1.152.61',redis_port='6379';
var http=require('http');
var url=require('url');
var redis=require('redis'),
redisClient=redis.createClient(redis_port,redis_host);
redisClient.on("error",function(err){
console.log('redis error:', err);
});
You can’t perform that action at this time.