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
exports.getArticle = function (req, res) { | |
// get article | |
res.send(article); | |
}; | |
exports.postArticle = function (req, res) { | |
// create article (from req.body) | |
}; |
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.get('/arcticle', function (req, res){ | |
// get article from somewhere | |
res.send(article); | |
}); | |
app.post('/article', function (req, res) { | |
// create article | |
}); | |
app.put('/article', function (req, res) { |
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
// MVC PubSub and Chaining Explained in < 20 lines of JavaScript | |
// PubSub | |
var subscribers = []; | |
function publish(info) { | |
for (i in subscribers) { | |
subscribers[i].update(info); | |
} | |
}; |
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 Model = {}; | |
var View = {}; | |
var Controller = {}; |
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 express = require('express'); | |
var app = module.exports = express.createServer(); | |
// Configuration | |
app.configure(function(){ | |
app.set('views', __dirname + '/views'); | |
app.set('view engine', 'ejs'); | |
app.use(express.bodyParser()); |
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
import sublime, sublime_plugin, re | |
class autojslint(sublime_plugin.EventListener): | |
def on_post_save(self, view): | |
settings = sublime.load_settings("autojslint.sublime-settings") | |
if re.search( settings.get( "filename_filter" ), view.file_name() ): | |
view.window().run_command( "build" ) |
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
// Toggle commented blocks of code with a single slash | |
// open comment: /* | |
// close comment: // */ | |
// uncomment: //* | |
// pivot comment /*/ | |
/* | |
"commented" | |
// */ |
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
// how we create the specialized callbacks | |
function createCallback(index) { | |
return function (err, result) { | |
var next = steps[index+1]; | |
var cb = callbacks[index+1]; | |
if (err) { | |
console.log('Error: ' + err.message); | |
} else if (result) { | |
console.log('Result: ' + JSON.stringify(result)); | |
} |
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
// now we invoke the first function with the first callback | |
// sit back and watch the functions execute one by one... | |
steps[0](callbacks[0]); |
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
// here we create a callback for each function in our list above | |
for (var i = 0; i < steps.length; i++) { | |
callbacks[i] = createCallback(i); | |
} |