This file contains hidden or 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 Foundation | |
import PlaygroundSupport | |
let apiKey = "[API KEY]" | |
let endPointUrl = "https://westus.api.cognitive.microsoft.com/emotion/v1.0" | |
let url = URL(string: "\(endPointUrl)/recognize")! | |
let testImageString = "https://pbs.twimg.com/profile_images/853106910861643776/tZh0rhmL.jpg" | |
struct Response: Decodable { | |
let scores: Score |
This file contains hidden or 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
module.exports = { | |
"env": { | |
"browser": false, | |
"node": true, | |
"es6": true, | |
"mocha": true, | |
}, | |
"rules": { | |
"no-param-reassign": [2, { "props": false }], | |
"no-console":0, |
This file contains hidden or 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 UIKit | |
// reference each view controller before UIApplicationMain runs | |
print(CustomViewController.self) | |
// The following is required because there's an impedence mismatch between | |
// `CommandLine` and `UIApplicationMain` <rdar://problem/25693546>. | |
let argv = UnsafeMutableRawPointer(CommandLine.unsafeArgv).bindMemory( | |
to: UnsafeMutablePointer<Int8>.self, | |
capacity: Int(CommandLine.argc) |
This file contains hidden or 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 prepare(for segue: UIStoryboardSegue, sender: Any?) { | |
super.prepare(for: segue, sender: sender) | |
guard | |
let viewController = segue.destination as? CustomViewController | |
else { return } | |
// compiler knows that CustomViewModel is our view model type | |
viewController.viewModel = CustomViewModel(data: "hello") | |
} |
This file contains hidden or 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 CustomViewModel { | |
let data: String | |
init(data: String) { | |
self.data = data | |
} | |
} | |
final class CustomViewController: ViewController<CustomViewModel> { | |
override func viewDidLoad() { |
This file contains hidden or 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 UIKit | |
public class ViewController<T>: UIViewController { | |
var viewModel: T! | |
override public func viewDidLoad() { | |
super.viewDidLoad() | |
assertViewModel() | |
} | |
} |
This file contains hidden or 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 UIKit | |
print(DerivedViewController.self) | |
// The following is required because there's an impedence mismatch between | |
// `CommandLine` and `UIApplicationMain` <rdar://problem/25693546>. | |
let argv = UnsafeMutableRawPointer(CommandLine.unsafeArgv).bindMemory( | |
to: UnsafeMutablePointer<Int8>.self, | |
capacity: Int(CommandLine.argc) | |
) |
This file contains hidden or 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 CustomViewModel { | |
let data: String | |
init(data: String) { | |
self.data = data | |
} | |
} | |
final class CustomViewController: ViewController<CustomViewModel> { | |
override func viewDidLoad() { |
This file contains hidden or 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
#!/bin/sh | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
FILE="$DIR/../Design/appicon-foreground.svg" | |
OUTPUT_LOCATION="$DIR/../iTunes" | |
# convert svg asset to png | |
convert -density 2000 -resize 1024x1024 -background none $FILE appicon-foreground.png |
This file contains hidden or 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
func shortTimeAgoSinceDate(date: NSDate) -> String { | |
let calendar = NSCalendar.currentCalendar() | |
let unitFlags = NSCalendarUnit.CalendarUnitMinute | NSCalendarUnit.CalendarUnitHour | NSCalendarUnit.CalendarUnitDay | NSCalendarUnit.CalendarUnitWeekOfYear | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitYear | NSCalendarUnit.CalendarUnitSecond | |
let now = NSDate() | |
let earliest = now.earlierDate(date) | |
let latest = (earliest == now) ? date : now | |
let components:NSDateComponents = calendar.components(unitFlags, fromDate: earliest, toDate: latest, options: nil) | |
if (components.year >= 1) { | |
return "\(components.year)y" |