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
| voteCounts = exports.voteCounts = function(event, callback) { | |
| db.view('event', 'all', {startkey: [event._id], endkey: [event._id, {}, {}], group_level: 2}, function(err, body) { | |
| if (err) { | |
| callback(err); | |
| } | |
| else { | |
| // populate count for voteoptions | |
| event.voteoptions.forEach(function(vo, i){ | |
| var found = _und.find(body.rows, function(x) {return x.key[1] == vo.id}); | |
| vo['votes'] = (found? found.value : 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
| /Users/crabasa/Code/tmp/votr-part3/node_modules/nano/node_modules/errs/lib/errs.js:167 | |
| merged.stacktrace = err.stack.split("\n"); | |
| ^ | |
| TypeError: Object fabric_doc_update:handle_message/3,rexi_utils:process_mailbox/6,rexi_utils:recv/6,fabric_doc_update:go/3,fabric:update_docs/3,chttpd_db:db_req/2,chttpd:handle_request/1,mochiweb_http:headers/5 has no method 'split' | |
| at Object.exports.merge (/Users/crabasa/Code/tmp/votr-part3/node_modules/nano/node_modules/errs/lib/errs.js:167:33) | |
| at Request._callback (/Users/crabasa/Code/tmp/votr-part3/node_modules/nano/nano.js:311:28) | |
| at Request.init.self.callback (/Users/crabasa/Code/tmp/votr-part3/node_modules/nano/node_modules/request/main.js:122:22) | |
| at Request.EventEmitter.emit (events.js:91:17) | |
| at Request.<anonymous> (/Users/crabasa/Code/tmp/votr-part3/node_modules/nano/node_modules/request/main.js:661:16) | |
| at Request.EventEmitter.emit (events.js:115:20) |
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
| ~/Code/scripts | |
| เฒ _เฒ node -e 'require("http").createServer(function(q,s){console.error(q.headers);s.end("ok");this.close()}).listen(1337)' & | |
| [1] 50947 | |
| ~/Code/scripts | |
| เฒ _เฒ cat foo.py #!/usr/bin/env python | |
| import urllib | |
| response = urllib.urlopen("http://localhost:1337") | |
| print response |
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 arr = ['a', 'b', 'c']; | |
| for (i in arr) { | |
| if (i === 0) { | |
| console.log('do something special') | |
| } | |
| } | |
| // sadly, that console.log never happens |
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
| socket.on('vote', function(data) { | |
| vote = parseInt(data); | |
| index = vote - 1; | |
| votes = chart.series[0].data[index].y; | |
| chart.series[0].data[index].update(votes+1); | |
| }); |
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 socket = io.connect(); | |
| socket.on('connect', function() { | |
| console.log("Connected, lets sign-up for updates about votes for this event"); | |
| socket.emit('event', '{{ shortname }}'); | |
| }); |
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
| socketio = require('socket.io') | |
| // Attach socket.io to our web server | |
| io = socketio.listen(server); | |
| io.configure('development', function(){ | |
| io.set('log level', 1); | |
| }); | |
| io.sockets.on('connection', function(socket) { |
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 chartdata = [], | |
| labels = []; | |
| voting.forEach(function(vo, i) { | |
| // the number of votes | |
| chartdata.push(vo.votes); | |
| // the label for this data point | |
| labels.push(vo.name+' - '+(i+1)); | |
| }); |
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
| String.prototype.unescapeHtml = function () { | |
| var temp = document.createElement("div"); | |
| temp.innerHTML = this; | |
| var result = temp.childNodes[0].nodeValue; | |
| temp.removeChild(temp.firstChild); | |
| return result; | |
| } |
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 data = "{{ voteoptions }}"; | |
| var voting_string = data.unescapeHtml(); | |
| var voting = JSON.parse(voting_string); |