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 = express() | |
app.use(express.static(process.argv[3])); | |
app.listen(process.argv[2]) |
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 path = require('path') | |
var express = require('express') | |
var app = express() | |
app.use(require('stylus').middleware(process.argv[3])); | |
app.use(express.static(process.argv[3])); | |
app.listen(process.argv[2]) |
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 = express() | |
app.put('/message/:id', function (req, res) { | |
var id = req.params.id | |
var str = require('crypto') | |
.createHash('sha1') | |
.update(new Date().toDateString().toString() + id) | |
.digest('hex') | |
res.send(str) |
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 = express() | |
app.get('/search', function (req, res) { | |
res.send(req.query) | |
}) | |
app.listen(process.argv[2]) |
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 fs = require('fs') | |
var app = express() | |
app.get('/books', function (req, res) { | |
fs.readFile(process.argv[3], function (err, data) { | |
var jsonFromFile = JSON.parse(data.toString()); | |
res.json(jsonFromFile) | |
}) |
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 countWords(arr) { | |
return arr.reduce(function(prev, curr) { | |
prev[curr] = prev[curr] + 1 || 1 | |
return prev | |
}, {}) | |
} |
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 reduce(arr, fn, initial) { | |
function justDoOne(index, value) { | |
if (index >= arr.length) { | |
return value | |
} | |
return justDoOne(index + 1, fn(value, arr[index])) | |
} | |
return justDoOne(0, initial) | |
} |
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 duckCount() { | |
return Array.prototype.slice.call(arguments).filter(function(obj) { | |
return Object.prototype.hasOwnProperty.call(obj, 'quack') | |
}).length | |
} | |
module.exports = duckCount |
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(namespace) { | |
return console.log.bind(console, namespace) | |
} |
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 arrayMap(arr, fn) { | |
return arr.reduce(function (acc, current) { | |
acc.push(fn(current)) | |
return acc | |
}, []) | |
} |