Skip to content

Instantly share code, notes, and snippets.

View prabod's full-sized avatar

Prabod Rathnayaka prabod

View GitHub Profile
app.get('/', function(req, res) {
res.render('index');
});
// PROFILE SECTION =========================
app.get('/profile', isLoggedIn, function(req, res) {
res.render('profile', {
user: req.user
});
});
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
@prabod
prabod / User.js
Last active February 9, 2017 05:26
// define the schema for our user model
var userSchema = mongoose.Schema({
local : {
first_name : String,
last_name : String,
email : String,
password : String,
},
facebook : {
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'),
@prabod
prabod / crossover.js
Created December 3, 2016 19:47
Crossover Function
/**
* 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 = [];
@prabod
prabod / selection.js
Last active December 3, 2016 19:44
Selection Procedure
/**
* Breed a New Generation of Chromosomes
* */
function breed() {
var totalFitness = 0;
var fittest;
var fit=0;
/**
@prabod
prabod / fitness.js
Created December 3, 2016 19:28
Fitness Function
/**
* 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){
@prabod
prabod / randomPopulation.js
Created December 3, 2016 19:09
Random Population
/**
* 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){
/**