Skip to content

Instantly share code, notes, and snippets.

View Andrew-Lees11's full-sized avatar

Andrew Lees Andrew-Lees11

View GitHub Profile
@Andrew-Lees11
Andrew-Lees11 / dataTask.swift
Created April 1, 2019 16:37
Example of dataTask producing a double callback on Swift 5 in linux
import XCTest
import Kitura
import Foundation
final class dataTaskTests: XCTestCase {
let router = Router()
func testExample() throws {
router.get("/", handler: getHandler)
Kitura.addHTTPServer(onPort: 8080, with: router)
import Foundation
import Kitura
import LoggerAPI
import Configuration
import CloudEnvironment
import KituraContracts
import Health
import KituraSession
public let projectPath = ConfigurationManager.BasePath.project.path
@Andrew-Lees11
Andrew-Lees11 / result.swift
Created March 6, 2019 14:41
Codable Routing with Result
// Shared code
struct User: Codable {
let name: String
let age: Int
}
router.post("/users", handler: postHandler)
// Users codable route without result
func postHandler(user: User, completion: (User?, RequestError?) -> Void ) {
guard user.name == "Andy" else {
@Andrew-Lees11
Andrew-Lees11 / couchDB.swift
Created November 15, 2018 13:46
CouchDB Sessions, Users and Config
// CouchDBClient
/// Returns a `UsersDatabase` instance.
public func usersDatabase() -> UsersDatabase {
return UsersDatabase(connProperties: self.connProperties, dbName: "_users")
}
// MARK: Config
/// Set a CouchDB configuration parameter to a new value.
/*
* Copyright IBM Corporation 2016
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
// ChatServer is a very simple chat server
import Foundation
import KituraWebSocket
import Foundation
class ChatService: WebSocketService {
private var connections = [String: ConnectionWrapper]()
// ChatServer is a very simple chat server
import Foundation
import KituraWebSocket
import Foundation
class ChatService: WebSocketService {
var gameTimer: Timer!
/**
* Copyright IBM Corporation 2018
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@Andrew-Lees11
Andrew-Lees11 / gist:80253ffab4cedc83fbf1f78bb6d91dc2
Created June 1, 2018 01:24
TypeSafeCreds Redirect unauthorized
/**
* Copyright IBM Corporation 2018
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*