Skip to content

Instantly share code, notes, and snippets.

View kjessup's full-sized avatar

Kyle Jessup kjessup

  • Treefrog
  • Newmarket, Ontario
View GitHub Profile
import PerfectHTTP
import PerfectHTTPServer
import PerfectSMTP
import PerfectFileMaker
let fms = FileMakerServer( host: "127.0.0.1", port: 8180, userName: "username", password: "password" )
fms.databaseNames {
result in
do {
import PerfectHTTP
import PerfectHTTPServer
import Dispatch
let serial = DispatchQueue(label: "serial")
var mul = 1
struct NotEmpty: Codable {
let str: String
init() {
str = serial.sync {
let mulVal = String(repeating: "\(mul)", count: mul)
* thread #6, name = 'NIO-ELT-#0'
* frame #0: 0x00007ffff7c88908 libswiftCore.so`std::pair<(anonymous namespace)::TupleCacheEntry*, swift::MetadataResponse> swift::LockingConcurrentMap<(anonymous namespace)::TupleCacheEntry, false, (anonymous namespace)::TupleCache>::getOrInsert<(anonymous namespace)::TupleCacheEntry::Key, swift::MetadataRequest&, swift::ValueWitnessTable const*&>((anonymous namespace)::TupleCacheEntry::Key, swift::MetadataRequest&&&, swift::ValueWitnessTable const*&&&) + 56
frame #1: 0x00007ffff7c88521 libswiftCore.so`swift_getTupleTypeMetadata + 241
frame #2: 0x00007ffff7c88dca libswiftCore.so`swift_getTupleTypeMetadata2 + 26
frame #3: 0x00007ffff7a5a232 libswiftCore.so`Swift.Range.init(uncheckedBounds: (lower: A, upper: A)) -> Swift.Range<A> + 50
frame #4: 0x00007ffff7b52f23 libswiftCore.so`Swift.Slice.subscript.getter : (A.Index) -> A.Element + 323
frame #5: 0x00007ffff7b53d99 libswiftCore.so`protocol witness for Swift.Collection.subscript.getter : (A.Index) -> A.Elem
//
// Shell.swift
// PerfectAssistant2
//
// Created by Kyle Jessup on 2017-03-30.
// Copyright © 2017 PerfectlySoft. All rights reserved.
//
import Foundation
import PerfectLib
extension CloudFormation.RDSInstance {
func authDb() throws -> Database<PostgresDatabaseConfiguration> {
return Database(configuration: try databaseConfiguration(database: biqAuthDatabaseName))
}
func databaseConfiguration() throws -> PostgresDatabaseConfiguration {
return try databaseConfiguration(database: biqAuthDatabaseName)
}
func databaseConfiguration(database: String) throws -> PostgresDatabaseConfiguration {
return try .init(database: database, host: hostName, port: hostPort, username: userName, password: password)
}
extension Route {
init<IN: Codable, OUT: Codable>(uri: String, _ handler: @escaping (IN) throws -> OUT) {
self.init(method: .post, uri: uri) {
req, resp in
do {
guard let body = req.postBodyBytes else {
throw DecodingError.dataCorrupted(.init(codingPath: [], debugDescription: "This request requires JSON input."))
}
let input = try JSONDecoder().decode(IN.self, from: Data(bytes: body))
resp.setBody(bytes: try JSONEncoder().encode(try handler(input)).map{$0})
func runProc(_ cmd: String, args: [String], envs: [String:String] = [:], quoteArgs: Bool = true, stderr: Bool = false, cd: String? = nil, read: ((String) -> ())? = nil) throws {
var ienvs = [("PATH", pathFromShell),
("HOME", ProcessInfo.processInfo.environment["HOME"]!),
("LANG", "en_CA.UTF-8")]
for e in envs {
ienvs.append(e)
}
let cmdPath = File(cmd).path
var newCmd: String
if let cd = cd {
import PerfectLib
import PerfectHTTP
import PerfectHTTPServer
let host1Routes = Routes([
Route(uri: "/") { _, resp in resp.appendBody(string: "host 1").completed() }
])
let host2Routes = Routes([
Route(uri: "/") { _, resp in resp.appendBody(string: "host 2").completed() }
])
var nonSecureRoutes = Routes()
nonSecureRoutes.add(method: .get, uri: "/**", handler: {
request, response in
response.setHeader(.location, value: "https://\(request.header(.host) ?? mainDomain)\(request.uri)")
.completed(status: .movedPermanently)
})
var secureRoutes = Routes()
secureRoutes.add(method: .get, uri: "/**", handler: {
request, response in
FROM ubuntu:16.04
LABEL perfectassistant="u16"
RUN apt-get -y update && apt-get install -y \
clang libicu-dev \
libcurl4-openssl-dev \
pkg-config \
git \
wget \
&& rm -rf /var/lib/apt/lists/*
RUN wget https://swift.org/builds/swift-3.0.2-release/ubuntu1604/swift-3.0.2-RELEASE/swift-3.0.2-RELEASE-ubuntu16.04.tar.gz \