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 Twilio = require('./twilio-js'); | |
Twilio.AccountSid = "AC57534a35a8284eb49d22b122fb5be0e6"; | |
Twilio.AuthToken = "bc80e083030a3c14638923c335c82854"; | |
Twilio.UsageRecord.all(function(err, res) { | |
res.usageRecords.forEach(function(record) { | |
// have at it! | |
}); | |
}); |
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 chart; | |
// Attach a handler to the window load event. | |
$(document).ready(function() { | |
chart = new Highcharts.Chart({ | |
chart: { | |
renderTo: 'chart', | |
type: 'bar' | |
}, | |
title: { |
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 event = function(req, res){ | |
events.findBy('shortname', req.params.shortname, function(err, event) { | |
if (event) { | |
// remove sensitive data | |
event.voteoptions.forEach(function(vo){ | |
delete vo.numbers; | |
}); | |
res.render('event', { | |
name: event.name, shortname: event.shortname, state: event.state, |
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
[ | |
{ | |
"id": 1, | |
"name": "foo", | |
"votes": 0 | |
}, | |
{ | |
"id": 2, | |
"name": "bar", | |
"votes": 0 |
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 data = "{{ voteoptions }}"; | |
var voting_string = data.unescapeHtml(); | |
var voting = JSON.parse(voting_string); |
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
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 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 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 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 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); | |
}); |