This file contains hidden or 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
| /** | |
| IntExtensions.swift | |
| Convert an arbitrary length byte array into a Swift Int | |
| <https://gist.github.com/tannernelson/e720877bf7700138eb99> | |
| */ | |
| extension Int { | |
| static func fromByteArray(bytes: [UInt8]) -> Int { |
This file contains hidden or 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
| // Returns `URL?` | |
| public enum SocketEndPoint: String { | |
| case eventSocket = "http://nowhere.com/events" | |
| case liveSocket = "http://nowhere.com/live" | |
| public var url: URL? { | |
| return URL(string: self.rawValue) | |
| } | |
| } |
This file contains hidden or 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
| // Copyright © 2016 Envoy. All rights reserved. | |
| /* | |
| Write a Swift playground that takes an n x n grid of integers. Each integer can be either 1 or 0. | |
| The playground then outputs an n x n grid where each block indicates the number of 1's around that block, (excluding the block itself) . For Block 0 on row 0, surrounding blocks are (0,1) (1,0) and (1,1). Similary for block (1,1) all the blocks around it are to be counted as surrounding blocks. | |
| Requirements: |
This file contains hidden or 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
| #!/bin/bash | |
| function show_code { | |
| ERROR_LOCATION=$(grep -Ron "\[UIImage imageNamed:\s*@\"$1\"\s*\]" $PROJECT_NAME) | |
| if [[ -z $ERROR_LOCATION ]]; then | |
| ERROR_LOCATION=$(grep -Ron "UIImage(named\:\s*\"$1\"\s*)" $PROJECT_NAME) | |
| fi | |
| ERROR_LOCATION=$(echo $ERROR_LOCATION | cut -d ':' -f 1,2) | |
| echo "$ERROR_LOCATION: error: Missing imageset with name $1" | |
| } |
This file contains hidden or 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
| require 'find' | |
| require 'pp' | |
| swift_file_paths = [] | |
| Find.find('./') do |path| | |
| if path =~ /.*\.swift$/ and !path.start_with? "./Carthage" | |
| swift_file_paths << path | |
| cmd = "xcrun swift-update -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -target arm64-apple-ios9 #{path} > convert.swift" | |
| system cmd |
This file contains hidden or 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
| //: Playground - noun: a place where people can play | |
| import UIKit | |
| //Coding Test - Envoy --- Swift 3 | |
| //Find sequence in integers in an array of integers | |
| //input: 5,6,7,8 | |
| //output: "5-8" | |
| //input: 2,5,6,7,8,10,14,17,18,25 |
This file contains hidden or 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
| /* | |
| Coding Test -- Envoy: | |
| Write a Swift playground that takes an n x n grid of integers. Each integer can be either 1 or 0. | |
| The playground then outputs an n x n grid where each block indicates the number of 1's around that block, (excluding the block itself) . For Block 0 on row 0, surrounding blocks are (0,1) (1,0) and (1,1). Similary for block (1,1) all the blocks around it are to be counted as surrounding blocks. | |
| Requirements: | |
This file contains hidden or 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 UIKit | |
| let ar = [2, 3, 4, 23, 4, 5, 13, 45, 23, 12, 13, 34, 45, 67, 23, 78] | |
| //check how many times O(n) crazy | |
| let duplicates = Array( | |
| Set( | |
| ar.filter({ (i: Int) in | |
| ar.filter({ | |
| $0 == i |
This file contains hidden or 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
| protocol ObservableProtocol { | |
| associatedtype T | |
| var value: T { get set } | |
| func subscibe(observer: AnyObject, block: @escaping (_ newValue: T, _ oldValue: T) ->()) | |
| func unsubscribe(observer: AnyObject) | |
| } | |
| public final class Observable<T>: ObservableProtocol { | |
| typealias ObserverBlock = (_ newValue: T, _ oldValue: T) -> () |
This file contains hidden or 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
| //Reference: | |
| //https://stackoverflow.com/questions/34709066/remove-duplicate-objects-in-an-array | |
| //https://medium.com/@YogevSitton/use-auto-describing-objects-with-customstringconvertible-49528b55f446 | |
| func uniq<S: Sequence, E: Hashable>(_ source: S) -> [E] where E == S.Iterator.Element { | |
| var seen = Set<E>() | |
| return source.filter { seen.update(with: $0) == nil } | |
| } |