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
@bp.route('/routes', methods=['GET']) | |
def get_routes(): | |
""" | |
A route to show registered routes. | |
:return: | |
""" | |
rules = [] | |
for rule in current_app.url_map.iter_rules(): | |
methods = ','.join(sorted(rule.methods)) |
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
from functools import wraps | |
def print_args(): | |
def decorator(func): | |
@wraps(func) | |
def func_wrapper(*args, **kwargs): | |
print('args: [%r], kwargs: [%r]' % (args, kwargs)) | |
return func(*args, **kwargs) | |
return func_wrapper | |
return decorator |
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
import cProfile | |
import pstats | |
import StringIO | |
pr = cProfile.Profile() | |
pr.enable() | |
iNot = set() | |
iFizz = set() | |
iBuzz = set() |
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
import cProfile | |
import pstats | |
import StringIO | |
pr = cProfile.Profile() | |
pr.enable() | |
threes = {num for num in range(3, 100, 3)} | |
fives = {num for num in range(5, 100, 5)} | |
not_in = {num for num in range(1, 100) if num not in threes and num not in fives} |
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
struct SelectedTagDetail { | |
var id: Int = 0 | |
var name: String = "" | |
} | |
typealias SelectedTagsClosure = (tags: [SelectedTagDetail]) -> Void | |
class BudgetTagsTableViewController: UITableViewController, BNDTableViewProxyDataSource { | |
// ... | |
var selectedTagIDs = Set<Int>() |
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
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { | |
if segue.identifier == "tag_table" { | |
let controller = segue.destinationViewController as! BudgetTagsTableViewController | |
//-- Pass in what we have as the selected tags | |
controller.selectedTagIDs = self.selectedTagIDs | |
//-- Closure to receive the selection list and create our tags_string | |
controller.onCloseSelectedTags = { [unowned self] tags in | |
self.selectedTagIDs = Set( tags.map { (tag) -> Int in tag.id } ) | |
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
// .... | |
let selectedIDsObservable = Observable(Set<Int>)() | |
// .... | |
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { | |
if segue.identifier == "tag_table" { | |
let controller = segue.destinationViewController as! BudgetTagsTableViewController | |
controller.selectedIDs = self.selectedIDsObservable | |
} | |
} |
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
private func bindDataToView(array: ObservableArray<BudgetTag>) | |
{ | |
self.bindDisposable = array.lift().bindTo(self.tableView, proxyDataSource: self) { indexPath, dataSource, tableView in | |
let cell = tableView.dequeueReusableCellWithIdentifier("tag_list_item", forIndexPath: indexPath) | |
let itemData = dataSource[indexPath.section][indexPath.row] | |
cell.textLabel?.text = itemData.tag | |
cell.detailTextLabel?.text = itemData.tag_description | |
} | |
} |
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
# Condensed for readablity | |
@inc_redis_counter(key=RedisKeys.REPLICATION_TRAFFIC_KEY_PREFIX) | |
def handle_replication_message(message): | |
data = json.loads(message) if isinstance(message, six.string_types) else message | |
rep_data = data.get('lookout_rep') # Replication data | |
category = rep_data.get('type') # The category | |
payload = rep_data.get('data') | |
if category == 'metrics': | |
view_handlers.handle_metrics_put(customer_num=customer_num, data=payload) |
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
@inc_redis_counter(key=RedisKeys.SITE_TRAFFIC_KEY_PREFIX) | |
def handle_site_detail_head(customer_num, data=None, remote_addr=None): | |
""" | |
:raises: Site.DoesNotExist | |
:unit_test: | |
:unit_test: head_bad_cust_num | |
:unit_test: head_unknown | |
""" | |
site = Site.objects.get(customer_num=customer_num) |
NewerOlder