Skip to content

Instantly share code, notes, and snippets.

View raymondfeng's full-sized avatar

Raymond Feng raymondfeng

View GitHub Profile
Statistical profiling result from /Users/rfeng/Demos/mssql-benchmark/v8-node-11.log, (114854 ticks, 208 unaccounted, 0 excluded).
[Unknown]:
ticks total nonlib name
208 0.2%
[Shared libraries]:
ticks total nonlib name
39 0.0% 0.0% /usr/lib/system/libsystem_pthread.dylib
33 0.0% 0.0% /usr/lib/system/libsystem_c.dylib
@raymondfeng
raymondfeng / gist:1637493e0fe12c1eade8
Created June 17, 2014 20:29
prototype properties
function X() {
}
Object.defineProperty(X.prototype, '__data',
{enumerable: false, configurable: true, writable: true, value: {x: 0}});
var x1 = new X();
console.log(Object.keys(x1));
console.log(x1.__data);
x1.__data = {x: 1};
@raymondfeng
raymondfeng / discovery-explorer.js
Created June 26, 2014 15:32
api explorer with discovered models
var loopback = require('loopback');
var path = require('path');
var app = module.exports = loopback();
var started = new Date();
/*
* 1. Configure LoopBack models and datasources
*
* Read more at http://apidocs.strongloop.com/loopback#appbootoptions
*/
module.exports = {
/**
* Declares a new hook to which you can add pres and posts
* @param {String} name of the function
* @param {Function} the method
* @param {Function} the error handler callback
*/
hook: function (name, fn, errorCb) {
if (arguments.length === 1 && typeof name === 'object') {
for (var k in name) { // `name` is a hash of hookName->hookFn
var loopback = require('loopback');
var path = require('path');
var app = module.exports = loopback();
app.set('restApiRoot', '/api');
var ds = loopback.createDataSource('soap',
{
connector: require('../index'),
@raymondfeng
raymondfeng / model-v2.js
Last active August 29, 2015 14:05
Generated loopback model from swagger api v2 specs
module.exports = function(Store) = {
/**
* Creates list of users with given input array
* @param {User} body List of user object
* @callback {Function} callback Callback function
* @param {Error|String} err Error object
* @param {Object} result Result object
*/
function createUsersWithListInput(body, callback) {
@raymondfeng
raymondfeng / model-v1.2.js
Created August 27, 2014 20:48
Generated loopback model from swagger api v1.2 specs
module.exports = function(SwaggerModel) = {
/**
* Find pet by ID
* @param {integer} petId ID of pet that needs to be fetched
* @callback {Function} callback Callback function
* @param {Error|String} err Error object
* @param {Pet} result Result object
*/
function getPetById(petId, callback) {
@raymondfeng
raymondfeng / pet-store-v2.json
Created August 27, 2014 20:55
Sample swagger 2.0 spec
{"swagger": 2.0, "info": {
"description": "This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.wordnik.com\">http://swagger.wordnik.com</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters",
"version": "1.0.0",
"title": "Swagger Sample App",
"termsOfService": "http://helloreverb.com/terms/",
"contact": {
"name": "apiteam@wordnik.com"
},
"license": {
"name": "Apache 2.0",
@raymondfeng
raymondfeng / create-admin-role.js
Created September 29, 2014 21:08
create-admin-role.js
var app = require('../app');
// Admin users
var adminUsers = require('../config/users.json').admins;
app.models.role.findOrCreate({where: {name: 'admin'}}, {name: 'admin'},
function (err, role) {
if (err) {
return console.error(err);
}
{
"initial": {
"favicon": {
},
"compress": {
"params": {
}
}
},