This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To be run under NodeJS | |
var util = require('util'); | |
function Parent() {} | |
Parent.tableName = 'parentTable'; | |
Parent.prototype.static_method = function() { | |
return this.constructor.tableName; | |
} | |
function Child() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var util = require('util'); | |
function Parent(){} | |
// Note we declare inheritance and static properties *before* the constructor | |
util.inherits(Child, Parent); | |
Child.static_property = 1; | |
function Child(){}; | |
var c = new Child(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var assert = require('assert'); | |
var util = require('util'); | |
var inheritance = require('./inheritance'); | |
function Person(name) { | |
this.name = name; | |
} | |
Person.prototype.greet = function() { | |
return "Hello "+this.name; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var async = require('async'); | |
exports.callPolygen = callPolygen; | |
function callPolygen(grm, callback) { | |
async.waterfall([ | |
function find(next) { | |
findGrm(grm, next); | |
}, | |
function exec(path, next) { | |
execPolygen(path, next); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Db = require('mongodb').Db, | |
Connection = require('mongodb').Connection, | |
Server = require('mongodb').Server; | |
var db = new Db('mongo-test', new Server("localhost", Connection.DEFAULT_PORT, {}), {native_parser:false}); | |
var context = this; | |
var onConnect = function(err, db) { | |
db.dropDatabase(function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// What's the best syntax to validate a JSON object? | |
var addr = { NamePrefixText: "Dr.", FirstName: "Lex", LastName: "Luthor", | |
Address: ["5 Upper Ter"], CityName: "SF" }; | |
Validate(addr, Address); // returns true if valid, errors go in an error object like AR | |
// Here are some possibilities: | |
// implicit type | |
var Address = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Assume our client object manages all communication with the server and other wonderful stuff | |
*/ | |
var Client = function(socket) { | |
var that = {}; | |
that.ping = function(limit, callback) { | |
var results = []; | |
return _ping(1, results, limit, callback); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.use(require('connect-flash')()); | |
// Expose the flash function to the view layer | |
app.use(function(req, res, next) { | |
res.locals.flash = function() { return req.flash() }; | |
next(); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var root = template: "something", data: {}, children: {} | |
function render(obj) | |
partials = {} | |
for each name, child in obj.children | |
partials[name] = render(child) | |
return mustache(obj.template, obj.data, partials) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$error = new My_API_Application_Response(My_API_Application_Response::FOOLISH_HUMAN_ERROR); | |
return $error; | |
// Oh no! I've typed My_API_Application_Response twice. This feels wrong! | |
// How about this? | |
return My_API_Application_Response::FOOLISH_HUMAN_ERROR(); |
OlderNewer