Skip to content

Instantly share code, notes, and snippets.

View shanev's full-sized avatar
💭
#BUIDL

shane.stars shanev

💭
#BUIDL
View GitHub Profile
@shanev
shanev / CustomViewController.swift
Last active February 23, 2018 20:09
Generic view controllers with storyboards and view model injection
struct CustomViewModel {
let data: String
init(data: String) {
self.data = data
}
}
final class CustomViewController: ViewController<CustomViewModel> {
override func viewDidLoad() {
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)
)
import UIKit
public class ViewController<T>: UIViewController {
var viewModel: T!
override public func viewDidLoad() {
super.viewDidLoad()
assertViewModel()
}
}
struct CustomViewModel {
let data: String
init(data: String) {
self.data = data
}
}
final class CustomViewController: ViewController<CustomViewModel> {
override func viewDidLoad() {
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")
}
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)
module.exports = {
"env": {
"browser": false,
"node": true,
"es6": true,
"mocha": true,
},
"rules": {
"no-param-reassign": [2, { "props": false }],
"no-console":0,
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
//
// LivePhotoUtil.swift
// Blink
//
// Created by Shane Vitarana on 6/2/17.
// Copyright © 2017 Blink. All rights reserved.
//
import Alamofire
import BlinkApi
@shanev
shanev / FaceEmotion.swift
Created April 4, 2018 13:19
Output emoji representing facial emotion for an image or video frame
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 = TEST_IMAGE
struct Response: Decodable {
let scores: Score