Skip to content

Commit 29dca45

Browse files
Matthew ConlenMatthew Conlen
Matthew Conlen
authored and
Matthew Conlen
committed
initial commit
0 parents  commit 29dca45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+3764
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
node_modules
3+
public

Makefile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
REPORTER = spec
2+
TESTS = test/*.js test/**/*.js test/**/**/*.js
3+
4+
test:
5+
@NODE_ENV=test NODE_PATH=./config:./app/controllers ./node_modules/.bin/mocha \
6+
--reporter $(REPORTER) \
7+
--ui tdd \
8+
$(TESTS)
9+
10+
.PHONY: test

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: NODE_ENV=production node server.js

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Lightning
2+
3+
A notebook for storing and sharing custom visualizations
4+
5+
6+
## mockups
7+
8+
### Stream of output for current interactive session
9+
10+
![feed](./mocks/feed.png)
11+
12+
### overview of an interactive session
13+
14+
![overview](./mocks/overview.png)
15+
16+
### sidebar showing options
17+
18+
![sidebar](./mocks/sidebar.png)
19+
20+
### permalink page for sharing
21+
22+
![viz](./mocks/viz-permalink.png)
23+
24+
25+
## installation
26+
27+
dependencies
28+
29+
* [node.js](http://nodejs.org/)
30+
* [mongodb](http://www.mongodb.org/)
31+
32+
33+
install by running `npm install`. Make sure mongo is running then launch the app by running
34+
35+
```
36+
gulp
37+
```
38+

app/controllers/home.js

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
/*!
3+
* Module dependencies.
4+
*/
5+
var graph = require('fbgraph');
6+
var _ = require('lodash');
7+
8+
exports.index = function (req, res) {
9+
res.render('index', {
10+
title: 'Node Express Mongoose Boilerplate'
11+
});
12+
};
13+
14+
15+
16+
exports.results = function(req, res) {
17+
18+
var nsp = req.io.of('/' + req.params.uid);
19+
20+
var categories = {};
21+
var totalPosts = 0;
22+
var sharedStory = 0;
23+
24+
var handleResults = function(err, res) {
25+
if(err) {
26+
console.log(err);
27+
return;
28+
}
29+
30+
if(res.data) {
31+
totalPosts += res.data.length;
32+
33+
// console.log('Got ' + res.data.length + ' results. ' + totalPosts + ' total posts fetched.');
34+
35+
_.each(res.data, function(d) {
36+
var category = d.from.category || 'People';
37+
categories[category] = (categories[category]) ? categories[category] + 1 : 1;
38+
39+
if(d.status_type && d.status_type === 'shared_story') {
40+
sharedStory++;
41+
}
42+
});
43+
}
44+
45+
if(res.paging && res.paging.next) {
46+
graph.get(res.paging.next, handleResults);
47+
}
48+
49+
50+
// console.log('');
51+
// console.log('Current Breakdown');
52+
// console.log('-----------------');
53+
// console.log(totalPosts + ' total posts');
54+
// console.log((sharedStory / totalPosts * 100).toFixed(2) + '% are links');
55+
56+
// console.log('');
57+
// _.each(_.sortBy(_.keys(categories), function(k) { return -categories[k]; }), function(key) {
58+
// var val = categories[key];
59+
// console.log((val / totalPosts * 100).toFixed(2) + '% from ' + key);
60+
// });
61+
// console.log('');
62+
63+
console.log('emitting update');
64+
nsp.emit('update', {
65+
totalPosts: totalPosts,
66+
sharedStory: sharedStory,
67+
categories: categories
68+
});
69+
70+
};
71+
72+
graph.get('/me/home', { access_token: req.user.accessToken}, handleResults);
73+
74+
75+
76+
res.render('results', {
77+
title: 'Analysis Results'
78+
});
79+
}

app/models/user.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
/*!
3+
* Module dependencies
4+
*/
5+
6+
var mongoose = require('mongoose');
7+
var userPlugin = require('mongoose-user');
8+
var findOrCreate = require('mongoose-findorcreate')
9+
10+
var Schema = mongoose.Schema;
11+
12+
/**
13+
* User schema
14+
*/
15+
16+
var UserSchema = new Schema({
17+
name: { type: String, default: '' },
18+
email: { type: String, default: '' },
19+
username: { type: String, default: '' },
20+
hashed_password: { type: String, default: '' },
21+
salt: { type: String, default: '' },
22+
accessToken: { type: String, default: '' }
23+
});
24+
25+
/**
26+
* User plugin
27+
*/
28+
29+
// UserSchema.plugin(userPlugin, {});
30+
UserSchema.plugin(findOrCreate);
31+
32+
/**
33+
* Add your
34+
* - pre-save hooks
35+
* - validations
36+
* - virtuals
37+
*/
38+
39+
/**
40+
* Methods
41+
*/
42+
43+
UserSchema.method({
44+
45+
});
46+
47+
/**
48+
* Statics
49+
*/
50+
51+
UserSchema.static({
52+
53+
});
54+
55+
/**
56+
* Register
57+
*/
58+
59+
mongoose.model('User', UserSchema);

app/views/index.jade

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extends layout
2+
3+
4+
//- block header
5+
include includes/header
6+
7+
8+
block content
9+
#content
10+
| :)

app/views/layout.jade

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
doctype html
2+
html(lang="en")
3+
head
4+
meta(name='viewport', content='width=device-width, initial-scale=1, maximum-scale=1')
5+
meta(http-equiv="X-UA-Compatible" content="IE=10; IE=9; IE=8; IE=7; IE=EDGE")
6+
meta(charset="UTF-8")
7+
block meta
8+
link(rel='stylesheet', href='#{STATIC_URL}css/app.css')
9+
10+
body
11+
block header
12+
block content
13+
14+
script(src='//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js')
15+
script(src='#{STATIC_URL}js/app.js')

config/config.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
/**
3+
* Module dependencies.
4+
*/
5+
6+
var path = require('path');
7+
var extend = require('util')._extend;
8+
9+
var development = require('./env/development');
10+
var test = require('./env/test');
11+
var production = require('./env/production');
12+
13+
var defaults = {
14+
root: path.normalize(__dirname + '/..')
15+
};
16+
17+
/**
18+
* Expose
19+
*/
20+
21+
module.exports = {
22+
development: extend(development, defaults),
23+
test: extend(test, defaults),
24+
production: extend(production, defaults)
25+
}[process.env.NODE_ENV || 'development'];

config/env/development.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
/**
3+
* Expose
4+
*/
5+
6+
module.exports = {
7+
db: 'mongodb://localhost/your_project_development',
8+
facebook: {
9+
clientID: 'APP_ID',
10+
clientSecret: 'SECRET',
11+
callbackURL: 'http://localhost:3000/auth/facebook/callback',
12+
scope: [
13+
'email',
14+
'user_about_me',
15+
'user_friends'
16+
]
17+
},
18+
google: {
19+
clientID: 'APP_ID',
20+
clientSecret: 'SECRET',
21+
callbackURL: 'http://localhost:3000/auth/google/callback',
22+
scope: [
23+
'https://www.googleapis.com/auth/userinfo.profile',
24+
'https://www.googleapis.com/auth/userinfo.email',
25+
'https://www.google.com/m8/feeds',
26+
]
27+
}
28+
};

config/env/production.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
/**
3+
* Expose
4+
*/
5+
6+
module.exports = {
7+
db: process.env.MONGOHQ_URL,
8+
facebook: {
9+
clientID: 'APP_ID',
10+
clientSecret: 'SECRET',
11+
callbackURL: 'http://localhost:3000/auth/facebook/callback',
12+
scope: [
13+
'email',
14+
'user_about_me',
15+
'user_friends'
16+
]
17+
},
18+
google: {
19+
clientID: 'APP_ID',
20+
clientSecret: 'SECRET',
21+
callbackURL: 'http://localhost:3000/auth/google/callback',
22+
scope: [
23+
'https://www.googleapis.com/auth/userinfo.profile',
24+
'https://www.googleapis.com/auth/userinfo.email',
25+
'https://www.google.com/m8/feeds',
26+
]
27+
}
28+
};

config/env/test.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
/**
3+
* Expose
4+
*/
5+
6+
module.exports = {
7+
db: 'mongodb://localhost/your_project_test',
8+
facebook: {
9+
clientID: 'APP_ID',
10+
clientSecret: 'SECRET',
11+
callbackURL: 'http://localhost:3000/auth/facebook/callback',
12+
scope: [
13+
'email',
14+
'user_about_me',
15+
'user_friends'
16+
]
17+
},
18+
google: {
19+
clientID: 'APP_ID',
20+
clientSecret: 'SECRET',
21+
callbackURL: 'http://localhost:3000/auth/google/callback',
22+
scope: [
23+
'https://www.googleapis.com/auth/userinfo.profile',
24+
'https://www.googleapis.com/auth/userinfo.email',
25+
'https://www.google.com/m8/feeds',
26+
]
27+
}
28+
};

0 commit comments

Comments
 (0)