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('/top', function(req, res){ | |
| db.keys('booking:*:name', function(err,keys){ | |
| if (err) { throw err; } | |
| if (typeof(keys.forEach) == 'undefined') { res.redirect('/battle'); } | |
| var bookings = []; | |
| var originalCount = 0; | |
| var returnCount = 0; | |
| try { keys.forEach(function(key){ | |
| key = String(key); | |
| var split = key.split(':'); |
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
| TypeError: Object 394 has no method 'forEach' | |
| at /home/ec2-user/jail/server.js:30:8 | |
| at Client.handleReply (/usr/local/lib/node/.npm/redis-node/0.2.7/package/lib/client.js:302:5) | |
| at Client.<anonymous> (native) | |
| at Client.emit (events:31:17) | |
| at Client.handleData (/usr/local/lib/node/.npm/redis-node/0.2.7/package/lib/client.js:242:18) | |
| at Stream.<anonymous> (native) | |
| at Stream.emit (events:31:17) | |
| at IOWatcher.callback (net:489:16) | |
| at node.js:773:9 |
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
| function adjust(ratings) { | |
| ratings[0] = ratings[0] ? parseFloat(ratings[0]) : 1000; | |
| ratings[1] = ratings[1] ? parseFloat(ratings[1]) : 1000; | |
| var winnerExpected = 1 / (1 + (Math.pow(10,(ratings[1] - ratings[0]) / 400))); | |
| var loserExpected = 1 / (1 + (Math.pow(10,(ratings[0] - ratings[1]) / 400))); | |
| var k = 30; | |
| var winnerAdjustment = Math.round(ratings[0] + (k * (1 - winnerExpected))); | |
| var loserAdjustment = Math.round(ratings[1] + (k * (0 - loserExpected))); | |
| return [winnerAdjustment, loserAdjustment]; | |
| } |
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'), | |
| app = express.createServer(); | |
| app.get('/', function(req, res){ | |
| res.send('Hello World'); | |
| }); | |
| app.listen(3000); |
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
| npm install express |
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 fs = require('fs'), | |
| redis = require('redis-node'), | |
| db = redis.createClient(), | |
| exec = require('child_process').exec; | |
| var files = fs.readdirSync('./new') | |
| files.forEach(function(file){ | |
| db.incr('images', function(err, id){ | |
| db.set('image:' + id + ':rating', '1000'); |
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){ | |
| db.keys('image:*:location', function(err,keys){ | |
| if (err) { throw err; } | |
| var offense = keys[Math.floor(Math.random()*keys.length)]; | |
| var defense = keys[Math.floor(Math.random()*keys.length)]; | |
| if (defense == offense) { | |
| defense = keys[Math.floor(Math.random()*keys.length)]; | |
| } | |
| db.mget('image:' + offense + ':location', 'image:' + offense + ':rating', | |
| 'image:' + defense + ':location', 'image:' + defense + ':rating', |
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
| <a href="/battle/<%- offense %>/<%- defense %>"> | |
| <img src="/images/<%- battle[0] %>" /><br /> | |
| Rating: <%- battle[1] %> | |
| </a> | |
| or | |
| <a href="/battle/<%- defense %>/<%- offense %>"> | |
| <img src="/images/<%- battle[2] %>" /><br /> | |
| Rating: <%- battle[3] %> | |
| </a> |
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('/battle/:winner/:loser', function(req, res){ | |
| if (req.params.winner && req.params.loser) { | |
| var winner = req.params.winner; | |
| var loser = req.params.loser; | |
| db.mget('image:' + winner + ':rating', | |
| 'image:' + loser + ':rating', | |
| function (err, ratings) { | |
| if (err) { throw err; } | |
| ratings[0] = ratings[0] ? parseFloat(ratings[0]) : 1000; | |
| ratings[1] = ratings[1] ? parseFloat(ratings[1]) : 1000; |
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
| <!doctype html> | |
| <html> | |
| <head> | |
| <title>FaceMash Clone</title> | |
| </head> | |
| <body> | |
| <%- body %> | |
| </body> | |
| </html> |
OlderNewer