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
// See notes in first comment | |
if let moc = AppDelegate.instance.managedObjectContext { | |
// fetching NSManagedObject with fancy generic typesafe helper method | |
if let allGrowers = moc.fetch(Grower.self, predicate: nil, sortDescriptors: nil, returnsObjectsAsFaults: true) { | |
switch allGrowers { | |
case .Value(let b): | |
let allGrowers = b.contents |
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 PathOverrideable(object): | |
def get_template(self, request, mode='', **kwargs): | |
try: | |
return self._path_overrideable_template | |
except AttributeError: | |
if not self.url: | |
return get_template(self.template) |
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
# Notes: | |
# Python 3 assumed, but shouldn't be hard to backport to Python 2 | |
# Cobbled together from two slightly different implementations, sorry for any inconsistencies. | |
# This creates two models, NavigationMenu, and NavigationMenuItem. A site can have many NavigationMenus, which are referenced from | |
# the template by location. E.g., 'footer', 'left_nav'. You can also create single-item lists for special purpose links/buttons, | |
# such a privacy_policy or homepage_cta. This helps to reduce hard coding in templates. | |
# NavigationMenuItem mixes in some different link types (Page, Document, URL) and presents them in a consistent way. It provides | |
# the ability to override the title of the referenced object. |
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
var dict = Dictionary<String,Bool>() | |
dict["a"] = true | |
dict["c"] = false | |
func matchOneOrTheOtherWithOptionals(a: Bool?, b: Bool?) -> String { | |
switch (a, b) { | |
case (.Some(true), let b) where b == .None || !b!: | |
return "a was true, but b was None or false" | |
case (let a, .Some(true)) where a == .None || a == .Some(false): |