Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
##Junaid's Coding Challenge Submission for Skyfit##
This submission is for the coding challenge listed below.

###How is the application run?

This is an express.js application. Please complete the following steps to run the app:

1. git clone this repository and this branch.
2. From the root of the code-challenge directory run: npm install
3. From the root of the code-challenge directory run: npm run
4. /listCommits -> Lists the recent commits in raw JSON format.
5. /authorCommits -> Lists all output as requested by the challenge.

###How are the unit tests run?

1. mocha /code-challenge/test/test.js


## NodeJS Programming Task

In order to be considered for the NodeJS position, you must complete the following steps.
Expand Down
60 changes: 60 additions & 0 deletions code-challenge/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var routes = require('./routes/index');
var users = require('./routes/users');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);
app.use('/users', users);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});


module.exports = app;
90 changes: 90 additions & 0 deletions code-challenge/bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

var app = require('../app');
var debug = require('debug')('code-challenge:server');
var http = require('http');

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
23 changes: 23 additions & 0 deletions code-challenge/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "code-challenge",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"bluebird": "^3.4.6",
"body-parser": "~1.15.1",
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"express": "~4.13.4",
"jade": "~1.11.0",
"morgan": "~1.7.0",
"serve-favicon": "~2.3.0"
},
"devDependencies": {
"github-api": "^2.3.0",
"mocha": "^3.1.2",
"supertest": "^2.0.0"
}
}
13 changes: 13 additions & 0 deletions code-challenge/public/stylesheets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}

a {
color: #00B7FF;
}
#numberResponse {

color: #E6F1F6;
}

86 changes: 86 additions & 0 deletions code-challenge/routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
var express = require('express');
var router = express.Router();
var path = require('path');

/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});

//This route lists the recent commits on the repository.
router.get('/listAllCommits', function(req, res, next) {


var GitHub = require('github-api');

// token auth
var gh = new GitHub({
//token: 'Not needed for a public repository'
});

var repo = gh.getRepo('nodejs', 'node');
console.log(repo);


repo.listCommits()
.then(function({data: commitsJson}) {
//console.log(commitsJson)
res.jsonp(commitsJson)
});


});


//This route does the following:
//1. Lists the last 25 commit SHAs on the node repository by author.
//2. Displays commit SHAs that end with a number and commit SHAs that do not end with a number.
//3. SHAs ending with a number are color coded.
router.get('/authorCommits', function(req, res, next) {

//Connect to Github via token authentication.

var GitHub = require('github-api');

// token auth
var gh = new GitHub({
//token: 'Not needed for a public repository'
});

//Access the nodejs repo directly.
var repo = gh.getRepo('nodejs', 'node');
console.log(repo);
repoParsed = JSON.stringify(repo)

//1. List all commits that belong to user: trott
//2. Check to see which SHA ends with an integer and which SHA does not.

repo.listCommits({author: 'trott'})
.then(function({data: authorCommitsJson}) {

var re = new RegExp('([0-9]+)$');
var numberResponse = [];
var nonNumberResponse = [];
for (var i=0; i<25; i++) {

if(authorCommitsJson[i].sha.match(re)) {


numberResponse.push("\n" + authorCommitsJson[i].sha)
}
else {

nonNumberResponse.push("\n" + authorCommitsJson[i].sha);


}

}
//Render the results in HTML:
res.render('index', {title: 'Junaid\'s Code Challenge for Skyfit!', repo: repoParsed, nonNumberResponse: nonNumberResponse, numberResponse: numberResponse});

});
});


module.exports = router;
45 changes: 45 additions & 0 deletions code-challenge/routes/npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle [email protected]~prestart: [email protected]
6 silly lifecycle [email protected]~prestart: no script for prestart, continuing
7 info lifecycle [email protected]~start: [email protected]
8 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true
9 verbose lifecycle [email protected]~start: PATH: /usr/lib/node_modules/npm/bin/node-gyp-bin:/home/hellroaster/example-nodejs-challenge/code-challenge/node_modules/.bin:/usr/bin:/usr/local/heroku/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
10 verbose lifecycle [email protected]~start: CWD: /home/hellroaster/example-nodejs-challenge/code-challenge
11 silly lifecycle [email protected]~start: Args: [ '-c', 'node ./bin/www' ]
12 silly lifecycle [email protected]~start: Returned: code: 1 signal: null
13 info lifecycle [email protected]~start: Failed to exec start script
14 verbose stack Error: [email protected] start: `node ./bin/www`
14 verbose stack Exit status 1
14 verbose stack at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/lib/utils/lifecycle.js:242:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:191:7)
14 verbose stack at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:191:7)
14 verbose stack at maybeClose (internal/child_process.js:852:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
15 verbose pkgid [email protected]
16 verbose cwd /home/hellroaster/example-nodejs-challenge/code-challenge/routes
17 error Linux 3.19.0-51-generic
18 error argv "/usr/bin/nodejs" "/usr/bin/npm" "start"
19 error node v6.4.0
20 error npm v3.10.3
21 error code ELIFECYCLE
22 error [email protected] start: `node ./bin/www`
22 error Exit status 1
23 error Failed at the [email protected] start script 'node ./bin/www'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the code-challenge package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error node ./bin/www
23 error You can get information on how to open an issue for this project with:
23 error npm bugs code-challenge
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls code-challenge
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
9 changes: 9 additions & 0 deletions code-challenge/routes/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var express = require('express');
var router = express.Router();

/* GET users listing. */
router.get('/', function(req, res, next) {
res.send('respond with a resource');
});

module.exports = router;
Loading