Skip to content

Instantly share code, notes, and snippets.

Avatar
🍙

Stephen Wan stephen

🍙
View GitHub Profile
View baseModelLoad.js
static load(token) {
return new Promise((resolve, reject) => {
this._createQuery().get(token).then((data) => {
resolve(new this(data));
}, (err) => {
if (err.code === 101) {
resolve(null); // model with token does not exist.
} else {
reject(new Error(err));
}
View proxyGetSet.js
static createProxyFromModel(model) {
return new Proxy(model, {
get: function(target, name) {
if (name in model.definition) {
return model.get(name);
} else {
return target[name];
}
},
set: function(target, name, value) {
View sessionBoodleModel.js
class Session extends BaseModel {
get definition() {
return {
user: 'string',
expirationTime: 'date'
};
}
// "instance methods"
View sessionMongooseModell.js
var Session = mongoose.model('Session', {
user: String,
expirationTime: Date
});
// "instance methods"
Session.methods.expire = function() { ... };
Session.methods.renew = function(date) { ... };
// "class methods"
View generatorSession.js
var session = yield Session.generate({ user: 'stephen' });
var token = session.token;
session.expirationTime = Date.now();
yield session.save();
// re-fetch
var fetchedSession = yield Session.load(token);
View promiseSession.js
var token = null;
Session.generate({ user: 'stephen' }).then(function(result) {
session.set('expirationTime', Date.now());
token = result.token;
return session.save();
}).then(function() {
View callbackSession.js
Session.generate({ user: 'stephen' }, function(err, result) {
var token = result.token;
session.set('expirationTime', Date.now());
session.save(function(err, result) {
// re-fetch
Session.load(token, function(err, fetchedSession) {
@stephen
stephen / data.log
Created Nov 13, 2014
airport express airplay log (soundcloud teardown)
View data.log
OPTIONS * RTSP/1.0
CSeq: 138
X-Apple-Device-ID: 0x80e650104f9c
Apple-Challenge: CY8Exs+7FfjQ9n17/3m0qg==
DACP-ID: 95482F9B7AEACEB
Active-Remote: 2783123138
User-Agent: AirPlay/215.10
RTSP/1.0 200 OK
Public: ANNOUNCE, SETUP, RECORD, PAUSE, FLUSH, TEARDOWN, OPTIONS, GET_PARAMETER, SET_PARAMETER, POST, GET
@stephen
stephen / gist:9f75655c87c00ae02e94
Created Nov 10, 2014
failed "could not connect to airsonos" log
View gist:9f75655c87c00ae02e94
OPTIONS * RTSP/1.0
CSeq: 0
X-Apple-Device-ID: 0x80e650104f9c
Apple-Challenge: b0m+LEonvoFTnJYrVo5Y1g==
DACP-ID: 95482F9B7AEACEB
Active-Remote: 67316247
User-Agent: AirPlay/215.10
RTSP/1.0 200 OK
CSeq:0
View buffer.log
<Buffer 20 00 00 04 00 13 08 09 2d f4 da 0a 0b fa b6 13 af 07 d2 d2 9e f7 ac 52 41 66 52 6b 42 c4 c3 86 87 c6 30 f0 d5 b2 6d 29 7a 7d 07 68 26 9e 3d f1 65 d0 f1 ...>
<Buffer 20 00 00 04 02 13 08 09 01 f4 7a 09 b3 fa a4 13 59 d5 0f 89 90 f2 84 15 ec a3 f8 c9 52 8c 21 37 bb 2d 6b ef 29 7f 53 ef c8 61 d3 14 f3 f3 b2 6d 53 cb 5e ...>
<Buffer 20 00 00 04 06 13 08 09 65 f4 b4 09 bb fa e6 13 c4 ad f8 18 c0 42 94 c6 e7 61 be e0 cb 74 08 cf a5 c1 b8 9e 30 f7 40 fd 6f 1a 1f 24 ca c4 e9 65 f9 11 86 ...>
<Buffer 20 00 00 04 04 13 08 09 35 f4 a2 09 dd fa d4 13 17 f0 75 68 09 3e f7 64 dc 60 28 f2 e4 de fb 2d 5d 0f 61 8c f7 db ff c2 d2 85 c6 31 dc de 9e 51 35 13 fb ...>
<Buffer 20 00 00 04 08 13 08 09 3d f4 9c 09 af fa 64 13 de 9e 55 ea 31 4f 04 1c 15 6c f8 3c 18 aa b4 84 98 92 b9 0a 91 8f ef 7c b3 88 ce 98 56 6f ce 11 a8 86 37 ...>
<Buffer 20 00 00 04 06 13 08 09 5d f4 b2 09 dd fa 32 13 34 93 b1 87 68 7b 70 ac 7a 8b 4d 3f 43 85 0e 57 96 8e 21 d2 06 93 b9 0d 51 d9 c7 14 ef 36 43 45 ba 5d c6 ...>
<Buffer 20 00 00 04 06 13 08