Skip to content

Instantly share code, notes, and snippets.

import Foundation
extension String
{
var length: Int {
get {
return count(self)
}
}
@curtisforrester
curtisforrester / doc_tags_code
Created September 25, 2015 13:48
A example of Python code tagged for doc_tags.
class CompileTags(object):
"""
Compiles a source module and extracts our tags from docstrings.
:unit_test_class: CompileTagsTests
"""
re_keyword_line = r':(unit_test[_a-z]*): *([a-zA-Z_]*)'
def __init__(self, module_name, verbose=False):
"""
:unit_test: create_instance
class CompileTagsTests(TestCase):
"""Auto-gen by DocTag"""
def setUp(self):
pass
def tearDown(self):
pass
def test_create_instance(self):
@curtisforrester
curtisforrester / atom_io_snippet.txt
Created September 25, 2015 14:18
Atom.io snippet to generate a Python method skeleton
'.source.python':
'Class method':
'prefix': 'defs'
'body': """
def ${1:foo}(self$2):
\\"\\"\\" $3
:unit_test:
\\"\\"\\"
"""
@api_view(['GET', 'PUT', 'DELETE', 'HEAD'])
@spy(persist=SPY_PERSIST, log=False, replicate=SPY_REPLICATE, category='site_updates')
def site_detail(request, customer_num):
pass
exchange = Exchange(CONSUMER_EXCHANGE, type='direct')
lookout_queue = Queue('lookout_rep', exchange, CONSUMER_QUEUE_ROUTING_KEY)
class LookoutConsumerStep(bootsteps.ConsumerStep):
def get_consumers(self, channel):
return [Consumer(channel, queues=[lookout_queue], callbacks=[self.handle_message], accept=['json'])]
def handle_message(self, body, message):
from DNotify.logic.replication import handle_replication_message
@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)
# 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)
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
}
}
// ....
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
}
}