Skip to content

Instantly share code, notes, and snippets.

View chriswebb09's full-sized avatar

Christopher Webb chriswebb09

View GitHub Profile
import UIKit
typealias TreeNode = TreeElement<Int>
enum Color { case r, b }
indirect enum TreeElement<T: Comparable> {
case empty
case node(Color, TreeElement<T>, T, TreeElement<T>)
func testDataStore() {
let dataSource = iTrackDataStore(searchTerm: "new")
let expect = expectation(description: "Data store calls APIClient to access server data and returns iTrack data array.")
dataSource.searchForTracks { tracks, error in
XCTAssert(tracks?.count == 49)
expect.fulfill()
}
@chriswebb09
chriswebb09 / APIClient.swift
Created April 18, 2017 04:02
Monitoring Downloads
import UIKit
typealias JSON = [String: Any]
final class iTunesAPIClient: NSObject {
var activeDownloads: [String: Download]?
weak var defaultSession: URLSession? = URLSession(configuration: .default)
// MARK: - Main session used
@chriswebb09
chriswebb09 / Bank.swift
Last active April 6, 2017 10:18
Bank example
enum Transaction {
case deposit, withdraw
}
class Bank {
typealias Account = (String, Double)
typealias AccountTransaction = (Double, Account) -> Account
static func deposit(amount : Double, account : (name : String, balance : Double)) -> Account {
@chriswebb09
chriswebb09 / linkcrawler.py
Last active April 6, 2017 11:15
Python Requests Example
#!/usr/bin/env python*
# -*- coding: UTF-8 -*-
import requests
import sys
import re
class WebCrawler:
def __init__(self):
import UIKit
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
class APIClient {
typealias JSON = [String: Any]
static func search(for query: String, page: Int, completion: @escaping (_ responseObject: JSON?, _ error: Error?) -> Void) {
import UIKit
typealias JSON = [String : Any]
fileprivate let imageCache = NSCache<NSString, UIImage>()
extension NSError {
static func generalParsingError(domain: String) -> Error {
return NSError(domain: domain, code: 400, userInfo: [NSLocalizedDescriptionKey : NSLocalizedString("Error retrieving data", comment: "General Parsing Error Description")])
}
}
@chriswebb09
chriswebb09 / Client.swift
Last active January 25, 2017 02:54
APIClients Swift
import UIKit
typealias JSONData = [String:Any]
struct APIClient {
let session = URLSession.shared
func createRequest(url: URL) -> URLRequest {
return URLRequest(url: url)
@chriswebb09
chriswebb09 / app.js
Created December 31, 2016 03:43
Basic NodeJS Server
var http = require('http');
var server = http.createServer(function(req,res) {
res.writeHead(200);
res.end('Hello world');
})
server.listen(8080);
@chriswebb09
chriswebb09 / APIClient.h
Created December 30, 2016 10:50
Objective-C APIClient
#import <Foundation/Foundation.h>
@interface APIClient : NSObject
@property(strong,nonatomic) NSString *urlString;
@property(strong, nonatomic) NSURL *url;
@property(strong, nonatomic) NSURLSessionDataTask *downloadTask;
-(void)sendAPICallWith:(void (^)(NSDictionary * dictionary))completionHandler;
-(id)initWithURLString:(NSString *)url;