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
// Option 1: if..elseif + optional unwrapping conditions | |
private func handleNotificationAction(id: String?, userInfo: [NSObject: AnyObject], responseInfo: [NSObject: AnyObject]?, completion: () -> Void) { | |
let taskId = userInfo["extra"]?["task_hash"] as? String | |
let projectId = userInfo["extra"]?["project_hash"] as? String | |
let comment = responseInfo?["UIUserNotificationActionResponseTypedTextKey"] as? String | |
if id == "comment", let task = taskId, comment = comment where !comment.isEmpty { | |
} else if id == "invitation_accept", let project = projectId { |
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
// APOD.swift | |
// Test with ReactiveCocoa 4 | |
// | |
// Created by Chris Patrick Schreiner on 17-11-2015. | |
import ReactiveCocoa | |
import Result | |
import XCPlayground | |
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true |
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
- (void)encodeRestorableStateWithCoder:(NSCoder *)coder { | |
[super encodeRestorableStateWithCoder:coder]; | |
[coder encodeObject:self.contentViewController | |
forKey:@"contentViewController"]; | |
} |
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
- (void)viewWillDisappear:(BOOL)animated { | |
[super viewWillDisappear:animated]; | |
UIViewController *root = self.presentingViewController.presentedViewController; | |
if (root.isBeingDismissed) { | |
[self.view endEditing:YES]; | |
} | |
} |
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
// Claim: flatMap<Result> and continueWith are the the same function | |
// | |
// Begin with flatMap and its dependencies | |
// | |
func flatMap<T,U>(x: Result<T>, f: T -> Result<U>) -> Result<U> { | |
return flatten(map(x, f)) | |
} | |
func map<T, U>(x: Result<T>, f: T -> U) -> Result<U> { |
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
Note that like all analogies, this is not a perfect one. I find it helps me think about it though. Also, don't try to draw conclusions about performance from this analogy :) | |
-[NSUserDefaults setObject:forKey:] is like... | |
<edit file to add key and value> | |
git add file | |
git commit | |
dispatch_after(some time, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
[[NSUserDefaults standardUserDefaults] synchronize] | |
}); |
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 'java.awt.Color) | |
(def *default-color-fraction* 0.2) | |
(def *default-blend-fraction* 0.5) | |
(defn- format-hex [c] | |
(str "#" (format "%02x%02x%02x" | |
(.getRed c) | |
(.getGreen c) |
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
(defn merge-seqs | |
"Merges sorted seqs of Comparable objects as in merge sort. Uses | |
left-to-right precedence order among the input seqs when duplicates | |
are present. Uses clojure.core/compare." | |
([xs ys] | |
(lazy-seq | |
(if (or (empty? xs) (empty? ys)) | |
(concat xs ys) | |
(let [x (first xs) | |
y (first ys)] |