Skip to content

Instantly share code, notes, and snippets.

[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 / 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)
@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 / swift-script
Last active May 15, 2016 05:15
A swift script to make dealing with new swift scripts a little easier :)
#!/usr/bin/env swift
#if os(OSX)
import Darwin
#else
import Glibc
#endif
import Foundation
/**
This class is used to keep a subscription to an event active.
Set all references to `nil` to no longer receive events
*/
public final class Subscription {
/**
Completiont to run on deinit.
@loganwright
loganwright / prebuild.sh
Created February 21, 2016 02:31
Run file as shell if exists
cd $BUILD_DIR
echo "-----> Running Prebuild.2"
if [ -f "./prebuild" ];
then
sh ./prebuild
else
echo "File does not exist."
fi
@loganwright
loganwright / docker
Created February 17, 2016 21:36
Zewo Docker File
from swiftdocker/swift
ENV DEBIAN_FRONTEND=noninteractive
run apt-get update; apt-get install -y libssl-dev
run mkdir /deps
workdir /deps
env zewo_version=0.2.0
@loganwright
loganwright / digitalocean.md
Last active February 14, 2016 00:46
digital ocean
@loganwright
loganwright / Heroku.md
Created February 13, 2016 04:59
SwiftServer.md

1: sign up and setup heroku. Create Heroku app etc.

** EVERYTHING PAST HERE ASSUMES CD IN REPOSITORY **

2: Set build packs: heroku buildpacks:set https://github.com/kylef/heroku-buildpack-swift.git

3: Start Heroku: heroku ps:scale web=1

4: Procfile: web: <#NameOfPackage#> --port=$PORT GOTCHAS

@loganwright
loganwright / featured.txt
Last active February 3, 2016 19:07
How to get featured in App Store - Orig from Kaden Wilkinson in iOS Developers Chat