This file contains 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 Sequelize = require('sequelize'); | |
var sequelize = new Sequelize(undefined, undefined, undefined, { | |
'dialect': 'sqlite', | |
'storage': __dirname + '/basic-sqlite-database.sqlite' | |
}); | |
var Profile = sequelize.define('profile', { | |
someData: Sequelize.STRING | |
}); |
This file contains 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
// ... | |
// POST /todos | |
app.post('/todos', middleware.requireAuthentication, function(req, res) { | |
var body = _.pick(req.body, 'description', 'completed'); | |
db.todo.create(body).then(function (todo) { | |
todo.setUser(req.user).then(function () { | |
res.json(todo); |
This file contains 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 Sequelize = require('sequelize'); | |
var sequelize = new Sequelize(undefined, undefined, undefined, { | |
'dialect': 'sqlite', | |
'storage': __dirname + '/basic-sqlite-database.sqlite' | |
}); | |
var Todo = sequelize.define('todo', { | |
description: { | |
type: Sequelize.STRING, | |
allowNull: false, |
This file contains 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 a = { | |
prop: { | |
nested: function (){ | |
console.log(this); | |
} | |
} | |
} | |
a.prop.nested() // return { nested: [Function] }, not the top level object |
This file contains 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 CronJob = require('cron').CronJob; | |
var job = new CronJob({ | |
cronTime: '00 00 00 * * *', | |
onTick: function() { | |
/* | |
* Run a 12:00am every night | |
*/ | |
}, | |
start: false | |
}); |
This file contains 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
// GET /companies/:companyId/tickets | |
{ | |
company: { | |
name: 'Some LLC' | |
// Other company fields | |
}, | |
tickets: [{ | |
id: 1, | |
userId: 23 | |
// Other ticket fields |
This file contains 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
// PART ONE - Query todos with user info included | |
Todo.findAll({include: [User]}).then(function(todos) { | |
todos.forEach(function (todo) { | |
console.log(todo.toJSON()); | |
}); | |
}, function() {}); | |
// Printed to screen for each todo | |
// You can get the username by calling todo.user.userName | |
// { |
This file contains 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 storage = require('node-persist'); | |
var crypto = require('crypto-js'); | |
storage.initSync(); | |
var accounts = []; | |
var argv = require('yargs').command('create', 'Create a new entry in the password manager', function(yargs) { | |
yargs.options({ | |
accountName: { | |
demand: true, | |
type: 'string', |
This file contains 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
function getAccountIndex(acctNumber) { | |
for (var i = 0; i < accounts.length; i++) { | |
var account = accounts[i]; | |
if (acctNumber === account.accountNumber) { | |
var index = accounts.indexOf(account); | |
console.log("Found it!"); | |
console.log("Index: " + accounts.indexOf(account)); | |
This file contains 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 obj = { | |
age: 25, | |
getAge () { | |
console.log(this.age); | |
} | |
} | |
obj.getAge(); |