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
// | |
// BasicUsageExampleTests.swift | |
// ExampleUITests | |
// | |
// Created by Shaun Hubbard on 10/28/17. | |
// Copyright © 2017 Shaun Codes. All rights reserved. | |
// | |
import XCTest | |
import Ambassador |
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
// every now and then I really find an enum to be the right construct for a data model | |
// in this case events have "eventTypes" and using pattern matching on the eventType is desirable | |
// eventTypes are based on a serverside array of possibilities "[private, public]" but theree is the possibility that | |
// this would be added to serverside so this should not nesecarily break the client implemenation | |
// to deal with this we need an unknown case | |
enum EventType: String, Decodable { | |
case `private` | |
case `public` | |
case unknown |
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 Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
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
// Per Tanner | |
let cache = \User.pets.prefetchCache() | |
let users = User.query(on: ...).filter(...).prefetching(\.pets, into: cache).all() // await | |
for user in users { | |
let pets = user.pets.get(from: cache) | |
} | |
// Shaun's idea | |
struct User: Model { | |
var pets: Childeren<User, Pet>? |
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 JWT | |
import Vapor | |
final class JWTService: Service { | |
var signer: JWTSigner | |
init(secret: String) { | |
signer = JWTSigner.hs512(key: Data(secret.utf8)) | |
} |
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
final class RouteLoggingMiddleware: Middleware, Service { | |
func respond(to request: Request, chainingTo next: Responder) throws -> Future<Response> { | |
let logger = try request.make(Logger.self) | |
let method = request.http.method | |
let path = request.http.uri.path | |
let query = request.http.uri.query | |
let reqString = "[\(method)]@\(path) with query:\(query)" |
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 | |
let anArray = [1, 2, 3, 4, 5] | |
extension Array where Element: Equatable { | |
func descendingElementalPairs() -> Array<Array<Element>> { | |
return self.enumerated() | |
.map { pair -> Array<Array<Element>> in | |
self[(pair.offset + 1)...].map { |
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
final class MyUser: PostgreSQLModel { | |
static let idKey: WritableKeyPath<MyUser, Int?> = \MyUser.id | |
var id: Int? | |
var myParticipationsCount: Int = 0 | |
init(id: Int? = nil) { | |
self.id = id | |
} | |
} |
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
final class Foo: PostgreSQLModel, Migration { | |
var id: Int? | |
} | |
final class Bar: PostgreSQLModel, Migration { | |
var id: Int? | |
} | |
final class Baz: PostgreSQLModel, Migration { |
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
router.get("teapot") { req -> Response in | |
let resp = req.makeResponse() | |
resp.http.status = .custom(code: 418, reasonPhrase: "I am teapot") | |
return resp | |
} |