Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's only moderately insane.... #11

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
1 change: 1 addition & 0 deletions .gititnore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
129 changes: 129 additions & 0 deletions Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
function _randInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}

var dataObject = {};

dataObject.generatePerson = function() {
let person = {
likes: [],
dislikes: [],
biography: [],
resume: []
};

// Generate likes and dislikes
for (let _ = 0; _ < 8; _++) {
person.likes.push(
dataObject.likeOptions[_randInt(0, dataObject.likeOptions.length)]
);
}
for (let _ = 0; _ < 8; _++) {
person.dislikes.push(
dataObject.likeOptions[_randInt(0, dataObject.likeOptions.length)]
);
}

// Generate Biography
for (let _ = 0; _ < 3; _++) {
person.biography.push(
dataObject.sentences[_randInt(0, dataObject.sentences.length)]
);
}

//Generate
for (let _ = 0; _ < 5; _++) {
let job = { title: '', body: [] };
job.title = dataObject.jobs[_randInt(0, dataObject.jobs.length)];
for (let _ = 0; _ < 4; _++) {
job.body.push(dataObject.history[_randInt(0, dataObject.history.length)]);
}
job.body = job.body.join(', ');
person.resume.push(job);
}

return person;
};

dataObject.sentences = [
'How was the math test?',
'Everyone was busy, so I went to the movie alone.',
'She did not cheat on the test, for it was not the right thing to do.',
'Hurry!',
'Tom got a small piece of pie',
'If Purple People Eaters are real… where do they find purple people to eat?',
'Wednesday is hump day, but has anyone asked the camel if he’s happy about it?',
'Cats are good pets, for they are clean and are not noisy.',
'The shooter says goodbye to his love.',
'I was very proud of my nickname throughout high school but today- I couldn’t be any different to what my nickname was.'
];

dataObject.history = [
'administered',
'analyzed',
'appointed',
'approved',
'assigned',
'attained',
'authorized',
'chaired',
'considered',
'consolidated',
'contracted',
'controlled',
'converted',
'coordinated',
'decided',
'delegated',
'developed',
'directed',
'eliminated',
'emphasized',
'enforced',
'enhanced',
'established',
'executed',
'generated'
];
dataObject.jobs = [
'Baggage handler',
'Bailiff',
'Baker',
'Bank clerk',
'Bank manager',
'Bar staff',
'Barber',
'Barrister',
'Beauty therapist',
'Blacksmith',
'Boat builder',
'Bodyguard'
];
dataObject.likeOptions = [
'triacetyloleandomycin',
'chorioepitheliomata',
'overindividualization',
'disestablishmentarianism',
'magnetothermoelectricity',
'antiutilitarianism',
'polytetrafluoroethylene',
'aerobacteriologically',
'bioelectrogenetically',
'phenylethylmalonylurea',
'interdenominationalism',
'cyclotrimethylenetrinitramine',
'magnetohydrodynamically',
'deoxyribonucleoprotein',
'anatomicopathological',
'antimaterialistically',
'trinitrophenylmethylnitramine',
'dicyclopentadienyliron',
'poliencephalomyelitis',
'overintellectualization',
'electrophysiologically',
'electrocardiographically'
];

module.exports = dataObject;
98 changes: 98 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
let express = require('express');
let uuid = require('uuid/v1');
let exphbs = require('express-handlebars');
let app = express();
var dataObject = require('./Data');
const port = process.env.PORT || '3000';

// parsers
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
var anythingReally = {};
var colorArray = ['Green', 'Red', 'Orange', 'Purple', 'Yellow', 'Blue'];

// Templates!
app.engine('handlebars', exphbs({ defaultLayout: 'main' }));
app.set('view engine', 'handlebars');

// POST middleware
app.use(bodyParser.urlencoded({ extended: true }));
// Cookie middleware
app.use(cookieParser());
// Static file middleware
app.use(express.static(`${__dirname}/public`));

app.get('/', (req, res) => {
// get status from cookie if it's set or use defaults
let theCookie = getCookie(req, res);
// Make sure we have a user object
let userObject = anythingReally[theCookie];
userObject = userObject || {
good: true,
food: 'Soylent Green',
color: 'Green',
insanity: 3
};
// Make sure that user has a person
if (!userObject.person) {
userObject.person = dataObject.generatePerson();
}

// Show the people
res.render('index', {
status: userObject,
colors: colorArray,
classes: getClasses(userObject)
});
});

app.post('/', (req, res) => {
let currentCookie = getCookie(req, res);
let person;
if (anythingReally[currentCookie]) {
person = anythingReally[currentCookie].person;
}
// parse post data
let formStatus = {
good: Boolean(Number(req.body.goodbad)),
food: req.body.food,
color: req.body.color,
insanity: req.body.insanity,
person: person
};

// set cookie
anythingReally[currentCookie] = formStatus;
res.redirect('back');
});

app.listen(port, () => {
console.log('Serving!');
});

function getCookie(req, res) {
// console.log(anythingReally);
let currentCookie = req.cookies.uuid;
if (!currentCookie) {
currentCookie = uuid();
}

res.cookie('uuid', currentCookie);
return currentCookie;
}

function getClasses(userObject) {
let classes = {
body: 'insanity-low',
html: userObject.color,
columns: +userObject.insanity + 1,
food: userObject.food
};

if (userObject.food.length > 10) classes.body = 'insanity-high';
if (!userObject.good)
classes.video =
'https://www.youtube.com/embed/RijB8wnJCN0?rel=0&amp;controls=0?ecver=1&autoplay=1';

return classes;
}
1 change: 1 addition & 0 deletions node_modules/.bin/handlebars

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/uglifyjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading