Skip to content

Instantly share code, notes, and snippets.

@loganwright
loganwright / swift-script-template.swift
Created May 15, 2016 05:09
Template for setting up swift scripts
#!/usr/bin/env swift
#if os(OSX)
import Darwin
#else
import Glibc
#endif
import Foundation
@loganwright
loganwright / FoundationServer.swift
Created June 29, 2016 18:57
Foundation Server - [WIP]
// http://stackoverflow.com/a/33729691/2611971
public class FoundationServer {
public static func listen(port: Int) {
let sock_fd = socket(AF_INET, SOCK_STREAM, 0);
if sock_fd == -1 {
perror("Failure: creating socket")
exit(EXIT_FAILURE)
}
var sock_opt_on = Int32(1)
[queue addOperationWithBlock:^{
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
NSURLSession *session = [NSURLSession sharedSession]; // or create your own session with your own NSURLSessionConfiguration
NSURLSessionTask *task = [session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (data) {
// do whatever you want with the data here
} else {
NSLog(@"error = %@", error);
@loganwright
loganwright / renaming.md
Last active August 4, 2016 19:29
Vapor Renaming
  • node
  • core - 0.3
  • swift
  • tls - 0.4
  • sqlite-driver
  • path-indexable - 0.3
  • polymorphic - 0.3
  • dashboard-example
  • website
  • postgresql-provider
@loganwright
loganwright / Queue.swift
Last active August 14, 2016 00:43
Possible Thread Queue
public class Queue {
private var strand: Strand! = nil
private var queue: [Strand.Closure] = []
private let lock = Lock()
public init(_ operation: Strand.Closure? = nil) throws {
if let operation = operation { queue.append(operation) }
strand = try Strand { [weak self] in
while let welf = self {
public final class HTML: Tag {
public let name = "html"
public func shouldRender(
stem: Stem,
context: Context,
tagTemplate: TagTemplate,
arguments: [Argument], value: Any?) -> Bool {
return true
}
@loganwright
loganwright / Fail-0.md
Last active August 31, 2016 01:56
libre
Compile CLibreSSL posix_win.c
Compile CLibreSSL v3_ia5.c
Compile CLibreSSL v3_bcons.c
Compile CLibreSSL sha1_one.c
Compile CLibreSSL ncbc_enc.c
Compile CLibreSSL bs_ber.c
Compile CLibreSSL ocsp_ext.c
Compile CLibreSSL d1_enc.c
Compile CLibreSSL v3_int.c
@loganwright
loganwright / docker.md
Last active April 30, 2017 02:56
Docker

Dockerfile

FROM ibmcom/swift-ubuntu:latest

# Install Vapor Toolbox
RUN curl -sL toolbox.vapor.sh | bash

# Set work dir to /vapor
WORKDIR /vapor

Enum Case Name

SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERFACE
const char *swift_EnumCaseName(OpaqueValue *value, const Metadata *type) {
  // Build a magic mirror. Unconditionally destroy the value at the end.
  const Metadata *mirrorType;
  const OpaqueValue *cMirrorValue;
  std::tie(mirrorType, cMirrorValue) = unwrapExistential(type, value);
@loganwright
loganwright / diff.md
Last active April 24, 2017 14:18
Vapor API Diff -- 1.5.15 | 2.0.0-beta.18

Stable API...

==(_:_:)
Abort.metadata
Abort.status
AbortError
Accept
Accept.init(mediaType:preference:)
Accept.mediaType