This file contains 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
define formatted_decimal => type { | |
data public value::decimal, | |
private flags | |
public onCreate(flags = (:)) => { | |
.value = 0.0 | |
.flags = #flags | |
} | |
public onCreate(v::decimal, flags = (:)) => { | |
.value = #v |
This file contains 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
define map->find(one, two, ...)::staticarray => | |
(with key in (:#one, #two) + #rest or (:) | |
select .find(#key))->asStaticArray |
This file contains 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
define string->encodeBash() => '"'+regexp('([\\$`"\\\n])', `\\$1`, self)->replaceAll+'"' |
This file contains 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
// | |
// JSONConvertable.swift | |
// | |
// Created by Kyle Jessup on 2016-01-21. | |
// Copyright © 2016 Treefrog. All rights reserved. | |
// | |
// This program is free software: you can redistribute it and/or modify | |
// it under the terms of the GNU Affero General Public License as | |
// published by the Free Software Foundation, either version 3 of the | |
// License, or (at your option) any later version, as supplemented by the |
This file contains 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
public func PerfectServerModuleInit() { | |
Routing.Handler.registerGlobally() | |
Routing.Routes["GET", "/"] = { req in return Example(path: "index.mustache") } | |
} | |
struct Example: RequestHandler { | |
let path: String | |
init(path: String) { | |
self.path = path |
This file contains 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 Filter404: HTTPResponseFilter { | |
func filterBody(response: HTTPResponse, callback: (HTTPResponseFilterResult) -> ()) { | |
callback(.continue) | |
} | |
func filterHeaders(response: HTTPResponse, callback: (HTTPResponseFilterResult) -> ()) { | |
if case .notFound = response.status { | |
response.bodyBytes.removeAll() | |
response.appendBody(string: "The file \(response.request.path) was not found.") | |
response.setHeader(.contentLength, value: "\(response.bodyBytes.count)") |
This file contains 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
-lCOpenSSL link error? | |
Add to the PROJECT build settings > "Library Search Paths" = $(PROJECT_DIR) as "Recursive". | |
Add it to the project settings as a whole, not for individual targets. | |
Alternatively you can generate the project with the DEVELOPMENT-SNAPSHOT-2016-09-07-a+ toolchain. |
This file contains 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 PerfectLib | |
import PerfectHTTP | |
import PerfectHTTPServer | |
import PerfectThread | |
// Create HTTPs server. | |
func createHTTPSServer() -> HTTPServer { | |
let server = HTTPServer() | |
server.serverPort = 8181 | |
server.ssl = (sslCert: "cert.pem", sslKey: "key.pem") |
This file contains 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 PerfectLib | |
import PerfectHTTP | |
import PerfectHTTPServer | |
import PerfectThread | |
import PerfectRequestLogger | |
Threading.getQueue(name: "nonsecureserver", type: .serial).dispatch { | |
let server = HTTPServer() | |
var routes = Routes() | |
routes.add(method: .get, uri: "/**", handler: { |
This file contains 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 PerfectCURL | |
let urls = ["http://localhost:8080/a", "http://localhost:8080/b", "http://localhost:8080/c", "http://localhost:8080/d"] | |
func fetchURLS(_ urls: [String], process: (_ url: String, _ headers: String?, _ body: String?) -> ()) { | |
struct curlTrack { | |
let url: String | |
let curl: CURL |
OlderNewer