Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Это файлики для моего второго скринкаста. Они еще проще, чем первые. Подробности можно http://shrtdb.com:8432/

View index.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
<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').click(function () {
var mash = $('li');
for (var i = mash.length - 1; i >= 0; i--) {
if (this == mash[i]) {
$.ajax({
url: '/vote/' + i,
method: 'POST',
success: function (data) {
changeValue(data)
}
})
};
};
})
});
function changeValue(data) {
$('.votescounter')[data.babe].innerHTML = 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>
View index.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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()
View index.html
1 2 3 4 5 6 7 8 9 10 11 12 13
body {
background-color: #f0f0f0;
}
 
ul {
list-style-type: none;
}
 
.votescounter {
font-size: 200px;
margin-left: 100px;
color: #505050;
}

Ишь какая кадавра на jQuery: я аж пароль от гитхаба вспомнил! Кажется, мои маленькие исправления (в форке) функциональность не рушат. Спасибо за скринкаст!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.