Skip to content
Browse files

Probably the most satisfying bit of JS I ever wrote, create_random_id().

  • Loading branch information...
1 parent b544420 commit 26c3ab09eae01938bc5c45379d9307ee98c1ccb6 Jonas Galvez committed Aug 29, 2010
Showing with 22 additions and 1 deletion.
  1. +22 −1 pagetalk.js
View
23 pagetalk.js
@@ -17,11 +17,32 @@ app.configure(function() {
// app.use(express.errorHandler());
// });
+poorsman_mongodb = {
+ 'voting_rooms': {}
+}
+
+create_random_id = function(len) {
+ var id = '', i = Math.ceil(len/2);
+ with(Math) while(i--)
+ id += (floor(random()*(256-15))+15).toString(16);
+ return id.substr(0, len);
+}
+
app.register('.html', require('ejs'));
app.set('view options', {'layout': false});
-app.get('/', function(req, res){
+app.get('/', function(req, res) {
res.render('index.html', {'locals': {'times': 10}});
});
+app.get('/voting-room/:id', function(req, res) {
+ res.render('voting-room.html', {'locals': {'voting_room_id': req.params.id}});
+});
+
+app.post('/voting-room', function(req, res) {
+ var voting_room_id = create_random_id();
+ poorsman_mongodb.voting_rooms[voting_room_id] = {};
+ res.redirect('/voting-room/' + voting_room_id);
+});
+
app.listen(80);

0 comments on commit 26c3ab0

Please sign in to comment.
Something went wrong with that request. Please try again.