Skip to content

Instantly share code, notes, and snippets.

View matmar10's full-sized avatar

Matthew Joseph Martin matmar10

View GitHub Profile
Verifying myself: My Bitcoin username is +matmar10. https://onename.io/matmar10
[
{
"step": "ADD_ADDRESS",
"points": 2
},
{
"step": "ADD_MOBILE",
"points": 3
},
{
@matmar10
matmar10 / update-user.js
Last active August 29, 2015 14:12
Express.js middleware the hard way
app.post('/user/:id', function (req, res) {
User.findOne({_id: ObjectId(req.params.id)}, function (err, user) {
validator.run(rules, req.body, function (errorCount, errors) {
user.merge(req.body);
user.save(function(err, savedUser) {
EmailClient.sendEmail(user.email, 'Your account was updated', function (err) {
res.status(200).send({
message: 'User updated'
});
});
@matmar10
matmar10 / update-user.js
Last active August 29, 2015 14:12
Express the easy way
app.post('/user/:id',
lookupUser,
validatePostBody,
mergeUser,
saveUser,
sendUserUpdatedEmail,
returnSuccess);
@matmar10
matmar10 / Gruntfile.js
Last active August 29, 2015 14:13
Sample Gruntfile for use with grunt-bower-update-main and grunt-wiredep
'use strict';
module.exports = function (grunt) {
// load all configured grunt tasks
require('load-grunt-tasks')(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
bowerUpdateMain: {
@matmar10
matmar10 / update-user.js
Last active August 29, 2015 14:13
Example express middleware flattened chain
var lookupUser, validateBody, mergeUser, saveUser, sendUserUpdatedEmail, returnSuccess;
lookupUser = function (req, res, next) {
User.findOne({
_id: new ObjectId(req.params.id)
}, function (err, user) {
if (err) {
res.status(500).send(err);
return;
}
@matmar10
matmar10 / update-user.js
Last active August 29, 2015 14:13
Express middleware the easy way with Passport
var sendEmailMiddleware = require('./middleware/send-email');
app.post('/user/:id',
passport.authenticate('bearer'),
lookupUser,
validatePostBody,
mergeUser,
saveUser,
sendEmailMiddleware('user-updated'),
returnSuccess);
@matmar10
matmar10 / architect-config.js
Last active August 29, 2015 14:13
Example Architect configuration
module.exports = [
"./plugins/user",
"./plugins/business"
];
@matmar10
matmar10 / example-directory-structure
Last active August 29, 2015 14:13
Sample Architect app directory structure
/src/
+-- app.js
+-- architect-config.js
+-- plugins/
+-- business/
+-- index.js
+-- package.json
+-- user/
+-- user.js
+-- package.json
@matmar10
matmar10 / app.js
Created January 10, 2015 22:45
Example Architect loadConfig usage
'use strict';
var architect = require('architect');
var path = require('path');
architect.loadConfig(path.join(__dirname, 'config.js'), function (err, architectConfig) {
if (err) {
console.error('Could not create Architect config:', err);
process.exit(1);
return;