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
app.get('/', function(req, res) { | |
res.render('index'); | |
}); | |
// PROFILE SECTION ========================= | |
app.get('/profile', isLoggedIn, function(req, res) { | |
res.render('profile', { | |
user: req.user | |
}); | |
}); |
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
passport.use('local-login', new LocalStrategy({ | |
// by default, local strategy uses username and password, we will override with email | |
usernameField: 'email', | |
passwordField: 'password', | |
passReqToCallback: true // allows us to pass in the req from our route (lets us check if a user is logged in or not) | |
}, | |
function(req, email, password, done) { | |
if (email) | |
email = email.toLowerCase(); // Use lower-case e-mails to avoid case-sensitive e-mail matching |
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
// define the schema for our user model | |
var userSchema = mongoose.Schema({ | |
local : { | |
first_name : String, | |
last_name : String, | |
email : String, | |
password : String, | |
}, | |
facebook : { |
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'), | |
bodyParser = require('body-parser'), | |
cookieParser = require('cookie-parser'), | |
cookieSession = require('cookie-session'), | |
serveStatic = require('serve-static'), | |
expressValidator = require('express-validator'), | |
passport = require('passport'), | |
crypto = require('crypto'), | |
flash = require('connect-flash'), | |
mongoose = require('mongoose'), |
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
/** | |
* Cross two Chromosomes and produce a child Chromosome | |
* */ | |
function crossover(chromosome1,chromosome2,rate,geneSize,chromoSize) { | |
var rand = Math.random(); // Random value for check crossover chance | |
if (rand < rate){ | |
var vString = []; |
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
/** | |
* Breed a New Generation of Chromosomes | |
* */ | |
function breed() { | |
var totalFitness = 0; | |
var fittest; | |
var fit=0; | |
/** |
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
/** | |
* Fitness Function | |
* fitness = 1 - (Square of pixel difference between chromosome and reference Image) | |
* ____________________________________________________________________ | |
* ( Resolution of the Image * count(RGBA) * Number of Possible Values) | |
* | |
* This fitness function stays inside [0,1] | |
* */ | |
fitness(width,height){ |
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
/** | |
* Generate random DNA for the Initial Generation | |
* Value Encoding is used for DNA encoding | |
* DNA = [RED, GREEN, BLUE, ALPHA, X1, Y1, X2, Y2, ...] | |
* */ | |
randomGenes(){ | |
var bString = []; | |
for (var i = 0; i < this.chromoSize; i+= this.geneSize){ | |
/** |