General advice on what to do and not to do.
function foo (err) {
if (!err) {| // mr.js -- very small request maker | |
| var http = require('http') | |
| , https = require('https') | |
| , url = require('url') | |
| var mr = module.exports = function mr (uri, callback) { | |
| uri = typeof(uri) === 'string' ? url.parse(uri, true) : uri; | |
| uri.method = uri.method || 'GET'; | |
| uri.headers = { host : uri.host, accept : 'text/html' }; |
brunch build --production
export DISPATCH_ASSETROOT=`pwd public`
nodemon)| // Server for serving 'index.html' and static assets | |
| // great for testing client-based apps (Ember/angular/backbone etc..) | |
| var port = parseInt(process.argv[2], 10) || 3000; | |
| require('http').createServer(function(req, res) { | |
| var file = /\.(png|jpg|gif|css|js|map)$/.test(req.url) ? req.url.slice(1) : 'index.html'; | |
| require('fs').readFile(file, function(err, data) { | |
| var mime = { | |
| 'html' : 'text/html', 'png' : 'image/png', 'gif' : 'image/gif', | |
| 'jpg' : 'image/jpeg', 'css' : 'text/css', 'js' : 'text/javascript' | |
| } [file.split('.').pop()] || 'application/octet-stream'; |
| // run with "mocha mocha-proc.js" | |
| var spawn = require('child_process').spawn | |
| , should = require('should') | |
| describe('your thing', function () { | |
| it('should do some stuff', function (done) { | |
| var ls = spawn('ls', ['-lh', '/usr']); |
| # var var var vs , , , | |
| - , , , | |
| - Leading Commas | |
| # declare on top of scope or near usage | |
| - Consistency is not compromised -- doesn't matter | |
| # Whenever makes sense name anonymous functions | |
| - _.map([], function () { |
| console.log('test test') |
| var fs = require('fs') | |
| , path = require('path') | |
| , app = require('express')() | |
| , Busboy = require('busboy'); | |
| function saveFiles(req, done) { | |
| var busboy = new Busboy({ headers : req.headers }); | |
| busboy.on('file', function(fieldname, file, filename, encoding, mimetype) { | |
| console.log(fieldname, file, filename, encoding, mimetype); | |
| // Pipe to fs or db, or res, or anywhere you want! |
| widgetCollections.map(function (widgetCollection) { | |
| return Object.keys(widgetCollection).reduce(function (widgets, widgetKey) { | |
| if (widget.isFrobbable()) { | |
| widgets.push({ | |
| widgetName: widgetKey, | |
| widgetValue: decombabulateWidgetValue({ | |
| decombobulator: config.getDecombobilator(), | |
| verbose: false | |
| }, widgetCollection[widgetKey]) | |
| }); |
| // Long-polling chat server + client. | |
| var chats = []; | |
| require('http').createServer(function(req, res) { | |
| if (/\/c/.test(req.url)) return res.end(chats.join('\n')); | |
| var m = req.url.split('='); | |
| if (m.length > 1) chats.unshift(m[1].replace(/\+/g, ' ')); | |
| res.end('<html><body><form><input name="m"></form><pre></pre><script>' | |
| + 'var r=new XMLHttpRequest;(function e(){r.open("GET","/c",true);r.send();r.onreadystatechange=function(){if(r.readyState==4){document.getElementsByTagName("pre")[0].innerHTML=r.responseText;setTimeout(e,1e3)}}})();document.forms[0].m.focus()' | |
| + '</script></body></html>') | |
| }).listen(parseInt(process.env.PORT, 10)|| 3000); |