This file contains 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 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 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 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 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> |
This file contains 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 byRating(a, b) { | |
var x = a[1]; | |
var y = b[1]; | |
return y - x; | |
} | |
app.get('/top', function(req, res){ | |
db.keys('image:*:location', function(err,keys){ | |
if (err) { throw err; } | |
var images = []; |
This file contains 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(), | |
redis = require('redis-node'), | |
db = redis.createClient(); | |
app.configure(function(){ | |
app.use(app.router); | |
app.use(express.staticProvider(__dirname + '/static')); | |
}); |
This file contains 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
<% for (var i in images) { var thisImage = images[i]; %> | |
<img src="/images/mugshots/<%- thisImage[0] %>" /><br /> | |
Rating: <%- thisImage[1] %><br /><br /> | |
<% } %> |
This file contains 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
# Redis Daemon configuration file example | |
# Note on units: when memory size is needed, it is possible to specifiy | |
# it in the usual form of 1k 5GB 4M and so forth: | |
# | |
# 1k => 1000 bytes | |
# 1kb => 1024 bytes | |
# 1m => 1000000 bytes | |
# 1mb => 1024*1024 bytes | |
# 1g => 1000000000 bytes |
This file contains 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
// t: current time | |
// b: beginning value | |
// c: change in value | |
// d: duration | |
var elast = function (t, b, c, d) { | |
var s=1.70158;var p=0;var a=c; | |
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; | |
if (a < Math.abs(c)) { a=c; var s=p/4; } | |
else var s = p/(2*Math.PI) * Math.asin (c/a); |