View get_idx_definitions.sql
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
SELECT tablename, | |
indexname, | |
indexdef | |
FROM pg_indexes | |
WHERE tablename = '$$table_name$$' |
View Retro.scala
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 spray.json._ | |
import DefaultJsonProtocol._ | |
object Main extends App { | |
class Card(val cardId: String, val name: String, val cardType: String, val effortHours: Double) { | |
def formatCard(idx: Int): String = { | |
idx + ". " + name + ": [" + effortHours + " hour(s)]" | |
} |
View example_2.py
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
class Subject(object): | |
def __init__(self): | |
self.observer_list = [] | |
def register_observer(obs): | |
self.observer_list.append(obs) | |
def remove_observer(obs): | |
if obs in self.observer_list: | |
self.observer_list.remove(obs) |
View example_1.py
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
class NewsGetterMachine(object): | |
def __init__(self): | |
self.news = None | |
def get_news(): | |
return self.news | |
def news_flash(): | |
news = self.get_news() |
View example_2.py
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
# Flying Behavior | |
class FlyBehavior(object): | |
def fly(): | |
raise NotImplementedError | |
class FlyWithWings(FlyBehavior): | |
def fly(): | |
print "I am flying!" | |
class FlyNoWay(FlyBehavior): |
View example_1.py
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
class Duck(object): | |
def quack(): | |
print "Quack! Quack!" | |
def swim(): | |
print "Yaay I am swimming!" | |
def display(): | |
raise NotImplementedError |
View my_model_index.py
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
class MyModelIndex(AutoPrepareTextIndexMixin, CelerySearchIndex, indexes.Indexable): | |
model_pk = indexes.IntegerField(model_attr='pk') # This is required | |
text = indexes.EdgeNgramField(document=True) # This too | |
some_boolean = indexes.IntegerField(model_attr='some_boolean') | |
# Filters should map to the exact field name that the admin will access them by. | |
# Example: foreign keys are accessed by FKModel__id. This is for filters | |
rel_model = indexes.IntegerField(model_attr='rel_model__id') | |
document_fields = ['name', 'nickname', 'rel_model__title'] # ^_^ |
View standard_analyzer_elastic_backend.py
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
class StandardAnalyzerElasticBackend(ElasticsearchSearchBackend): | |
SET_ANALYZE_STANDARD_FOR_SEARCH = getattr(settings, 'SET_ANALYZE_STANDARD_FOR_HAYSTACK_SEARCH', False) | |
DEFAULT_SETTINGS = { | |
'settings': { | |
"analysis": { | |
"analyzer": { | |
"ngram_analyzer": { | |
"type": "custom", | |
"tokenizer": "standard", | |
"filter": ["haystack_ngram", "lowercase"] |
View auto_prepare_text_index_mixin.py
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
class AutoPrepareTextIndexMixin(object): | |
""" | |
Used with Indexed Classes to add common functions: | |
1. Prepares text to be documented using fields from the list document_fields | |
2. Gets fields to be `select_related` for efficient db querying while indexing | |
3. Defines "get_updated_field" | |
Also tries to check for these modifications and raises errors if things not implemented like they should be | |
""" | |
def __init__(self): |
View update.py
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
def update_with_last_modified_time(qs, **kwargs): | |
# This function adds any auto_now field to the update call because QuerySet.update() doesn't do it :X | |
model_fields = qs.model._meta.get_fields() | |
fields_and_value_map = {} | |
for field in model_fields: | |
try: | |
auto_now = field.__getattribute__('auto_now') | |
except AttributeError: | |
auto_now = False |
NewerOlder