Skip to content

Instantly share code, notes, and snippets.

View chriswebb09's full-sized avatar

Christopher Webb chriswebb09

View GitHub Profile
switch(url.parse(request.url).pathname) {
case '/p1':
if (!error) {
response.end(data);
} else {
console.log(error);
}
case '/p2':
if (!error) {
response.end("Page 2");
import UIKit
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
class APIClient {
typealias JSON = [String: Any]
// search functionality stuff
}).listen(port, (error) => {
if (error) {
console.log('error ${ error }')
}
console.log('listening on ${ port }')
});
class Math {
func add(_ intOne: Int, _ intTwo: Int) -> Int {
return intOne + intTwo
}
}
import XCTest
@testable import ExampleProject
class ExampleProjectTests: XCTestCase {
override func setUp() {
super.setUp()
}
override func tearDown() {
import XCTest
import AVFoundation
@testable import Musicly
class MusiclyTests: XCTestCase {
// Boiler plate
func testDataStore() {
let dataSource = iTrackDataStore(searchTerm: "new")
func testDataStore() {
// Setup test
dataStore.searchForTracks { tracks, error in
XCTAssert(tracks?.count == 49)
expect.fulfill()
}
}
func testDataStore() {
// Setup
// Run test
waitForExpectations(timeout: 4) { error in
if let error = error {
XCTFail("waitForExpectationsWithTimeout error: \(error)")
}
}
protocol ImageDownloadProtocol {
func downloadImage(from url: URL, completion: @escaping (UIImage?) -> Void)
}
extension ImageDownloadProtocol {
func downloadImage(from url: URL, completion: @escaping (UIImage?) -> Void) {
let session = URLSession(configuration: .default)
DispatchQueue.global(qos: .background).async {
print("In background")
session.dataTask(with: URLRequest(url: url)) { data, response, error in
if error != nil {
print(error?.localizedDescription ?? "Unknown error")
}
if let data = data, let image = UIImage(data: data) {