Skip to content

Instantly share code, notes, and snippets.

View manuphatak's full-sized avatar
🎯
Focusing

Manu Phatak manuphatak

🎯
Focusing
View GitHub Profile
@manuphatak
manuphatak / cache_requests.py
Last active August 29, 2015 14:19
Persistent lru caching of the requests library. Stop spamming apis while you develop, starting now.
#!/usr/bin/env python
# coding=utf-8
"""
cache_requests
--------------
This module implements a basic LRU decorator that syncs calls with a redislite database.
ELI5: If you call the same function with the same parameters, it does not recalculate
the function. Instead, the first time, the results are stored, the second time the
@manuphatak
manuphatak / long_lines.py
Created April 2, 2015 15:56
long strings
url = 'https://www.reddit.com/r/learnpython/comments' \
'/2ztwnt/how_to_use_string_questions_on_quotes_str_i_have/'
alt = ('https://www.reddit.com/r/learnpython/comments'
'/2ztwnt/how_to_use_string_questions_on_quotes_str_i_have/')
# coding=utf-8
import collections
data = {'one': 1, 'two': 2, 'three': 3, 'a': 2}
sorted_data = collections.OrderedDict(sorted(data.items()))
print sorted_data
print sorted_data['three']
# coding=utf-8
def is_valid(input_):
"""validation rules"""
return input_ in '012345ABC'
while True:
choice = raw_input()
if is_valid(choice):
break