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
| console.log('starting password manager'); | |
| var crypto = require('crypto-js') | |
| var storage = require('node-persist'); | |
| storage.initSync(); | |
| var argv = require('yargs') | |
| .command('create', 'Create a new account', function (yargs) { | |
| yargs.options({ | |
| 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
| // POST /todos | |
| app.post('/todos', middleware.requireAuthentication, function(req, res) { | |
| var body = _.pick(req.body, 'description', 'completed'); | |
| db.sequelize.transaction(function(t) { | |
| var t; | |
| return db.todo.create(body).then(function(todo) { | |
| t = todo; | |
| return req.user.addTodo(todo) |
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
| function Account(balance) { | |
| this.balance = balance || 0; | |
| } | |
| Account.prototype.deposit = function(amount) { | |
| this.balance += amount; | |
| }; | |
| Account.prototype.withdraw = function(amount) { | |
| this.balance -= amount; |
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
| module.exports = function (sequelize, DataTypes) { | |
| return sequelize.define('todo', { | |
| description: { | |
| type: DataTypes.STRING, | |
| allowNull: false, | |
| validate: { | |
| len: [1, 250], | |
| isString: function (value) { | |
| if (typeof value !== 'string') { | |
| throw new Error('Description must be a string'); |
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
| sudo apt-get install curl | |
| curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash - | |
| sudo apt-get install -y nodejs |
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 request = require('request'); | |
| var cheerio = require('cheerio'); | |
| request('https://www.reddit.com/', function (error, response, body) { | |
| $ = cheerio.load(body); | |
| $('a.title').each(function (i, elem) { | |
| console.log(''); | |
| console.log('** Link ** ') | |
| console.log($(this).text()); |
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
| command('get', 'Get an existing account', function (yargs) { | |
| yargs.options({ | |
| name: { | |
| demand: true, | |
| alias: 'n', | |
| description: 'Account name (eg: Twitter, Facebook)', | |
| type: 'string' | |
| }, | |
| masterPassword: { | |
| demand: true, |
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
| return fetch(url, { | |
| method: 'post', | |
| headers: { | |
| 'Accept': 'application/json', | |
| 'Content-Type': 'application/json', | |
| 'Auth': localStorage.getItem('token') | |
| }, | |
| body: JSON.stringify({ | |
| email: userEmail, | |
| password: userPassword, |
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
| // Only part of file | |
| return fetch(url, { | |
| method: 'post', | |
| headers: { | |
| 'Accept': 'application/json', | |
| 'Content-Type': 'application/json', | |
| 'Auth': localStorage.getItem('token') | |
| }, | |
| body: JSON.stringify({ | |
| email: userEmail, |
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(function(err, req, res, next) { | |
| if (err instanceof SyntaxError) { // If invalid JSON | |
| res.status(500).json({error: "INVALID_JSON"}); | |
| } else if (err) { | |
| res.status(500).json({error: "SYSTEM_ERROR"}); | |
| } | |
| }); |