Skip to content

Instantly share code, notes, and snippets.

View sai-prasanna's full-sized avatar
🤖
=42

Sai sai-prasanna

🤖
=42
View GitHub Profile
import time
import sys
ms = int(sys.argv[1]) if len(sys.argv) > 1 else 250
words, start = 0, time.time()
print "\n"*2
try:
for line in sys.stdin:

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@sai-prasanna
sai-prasanna / gist:6240529
Created August 15, 2013 12:40
Merge Dictionary and update duplicates
from collections import Counter
a = {'a': 1}
b = {'a': 2, 'b': 3}
c = Counter(a) + Counter(b)
@sai-prasanna
sai-prasanna / Flask.py
Created August 12, 2013 05:53
Redirect url to correct one when id is correct. Consider blog with /id/slug as url for a specific post if user enters /id/foo it must redirect to /id/slug
@app.route('/post/<id>')
@app.route('/post/<id>/<slug>')
def view_post(id, slug=None):
post = models.Post.query.get_or_404(id)
if post.slug != slug:
return redirect(url_for('post', id=id,slug = post.slug))
return render_template("post.html", post=post)