Skip to content

Instantly share code, notes, and snippets.

@nomolosvulgaris
Forked from bobuk/index.html
Last active December 11, 2015 21:39
Show Gist options
  • Save nomolosvulgaris/4663974 to your computer and use it in GitHub Desktop.
Save nomolosvulgaris/4663974 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>Girls gone wild!</title>
<link rel="stylesheet" type="text/css" href="/static/style.css">
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript" src="http://localhost:8080/application.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var jug = new Juggernaut;
jug.subscribe('babes', function (data) {
changeValue(data);
});
$('li').each(function(i) {
$(this).click(function() {
$.ajax({
url: '/vote/' + i,
method: 'POST',
success: function (data) {
changeValue(data)
}
})
})
});
});
function changeValue(data) {
$('.votescounter').eq(data.babe).text(data.result);
};
</script>
</head>
<body>
<ul>
<li><img src="/static/babes/1.jpeg"/><span class="votescounter"></span></li>
<li><img src="/static/babes/2.jpeg"/><span class="votescounter"></span></li>
<li><img src="/static/babes/3.jpeg"/><span class="votescounter"></span></li>
<li><img src="/static/babes/4.jpeg"/><span class="votescounter"></span></li>
<li><img src="/static/babes/5.jpeg"/><span class="votescounter"></span></li>
</ul>
</body>
</html>
from flask import Flask, redirect, jsonify
from juggernaut import Juggernaut
from redis import Redis
app = Flask(__name__)
app.debug = True
db = Redis()
jug = Juggernaut()
@app.route('/')
def hello():
return redirect('/static/index.html')
@app.route('/vote/<int:voteid>', methods=['POST'])
def vote(voteid):
if voteid < 0 or voteid > 4:
return jsonify({'error': 'strange vote?!'})
res = db.incr('babes:vote:' + str(voteid))
result = {'result': res, 'babe': voteid}
jug.publish('babes', result)
return jsonify(result)
if __name__ == '__main__':
app.run()
body {
background-color: #f0f0f0;
}
ul {
list-style-type: none;
}
.votescounter {
font-size: 200px;
margin-left: 100px;
color: #505050;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment