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
/// This class centers the elements that fit on a given row/column | |
/// ripped off from https://github.com/Coeur/CollectionViewCenteredFlowLayout | |
/// modified to simplify and to remove forced unwrapping | |
open class CollectionViewCenteredFlowLayout: UICollectionViewFlowLayout { | |
open override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { | |
guard let elementsAttributes = super.layoutAttributesForElements(in: rect) | |
else { return nil } | |
guard let collectionView = collectionView | |
else { return elementsAttributes } |
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
typealias Constraint = (_ child: UIView, _ parent: UIView) -> NSLayoutConstraint | |
func equal<Axis, Anchor>(_ keyPath: KeyPath<UIView, Anchor>, _ to: KeyPath<UIView, Anchor>, _ constant: CGFloat = 0) -> Constraint where Anchor: NSLayoutAnchor<Axis> { | |
return { $0[keyPath: keyPath].constraint(equalTo: $1[keyPath: to], constant: constant) } | |
} | |
func equal<Axis, Anchor>(_ keyPath: KeyPath<UIView, Anchor>, _ constant: CGFloat = 0) -> Constraint where Anchor: NSLayoutAnchor<Axis> { | |
return equal(keyPath, keyPath, constant) | |
} |
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
- (void)testQueue { | |
dispatch_queue_t lockQueue = dispatch_queue_create("com.test.LockQueue", DISPATCH_QUEUE_SERIAL); | |
[self executeLockTest:^(VoidBlock block) { | |
dispatch_sync(lockQueue, ^{ | |
block(); | |
}); | |
}]; | |
} | |
- (void)disabled_testNoLock { |
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
func strings(from name: String) -> [String]? { | |
let date = Date() | |
guard let path = Bundle.main.path(forResource: name, ofType: "yaml") else { | |
return nil | |
} | |
do { | |
let fileString = try String(contentsOfFile: path, encoding: .utf8) | |
let fileTime = date.timeIntervalSinceNow | |
let lines = fileString.components(separatedBy:"\n") | |
let end = date.timeIntervalSinceNow |
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
- (NSArray *)stringsFromFile:(NSString *)name | |
{ | |
NSDate *start = [NSDate date]; | |
NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"yaml"]; | |
NSString *fileString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; | |
NSTimeInterval fileTime = [start timeIntervalSinceNow]; | |
NSArray *lines = [fileString componentsSeparatedByString:@"\n"]; | |
NSTimeInterval end = [start timeIntervalSinceNow]; | |
NSLog(@"end count:%.9f %.9f, %zd", fileTime, end, offsets.count); | |
return lines; |
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
extension String { | |
var length: Int { | |
return self.characters.count | |
} | |
subscript (i: Int) -> String { | |
return self[Range(i ..< i + 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
infix operator ??? : TernaryPrecedence | |
infix operator ||| : AdditionPrecedence | |
func ???(input: String?, valuesBlock: ((String?) -> String)) -> String { | |
return valuesBlock(input) | |
} | |
func |||(ifNotNil: String, ifNil: String) -> ((String?) -> String) { | |
return { (input: String?) -> String in | |
if let _ = input { |
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 | |
import PlaygroundSupport | |
///create a constraint of view to its superView | |
infix operator ➡️|: AdditionPrecedence | |
infix operator |⬅️: AdditionPrecedence | |
infix operator -⬆️: AdditionPrecedence | |
infix operator ⬇️-: AdditionPrecedence |
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 Foundation | |
var array = [Int]() | |
for i in 1 ..< 10000000 { | |
array.append(i) | |
} | |
//let numberList = array | |
extension Array where Element: Comparable { |
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
#!/usr/bin/swift | |
// Swift 3.0 | |
// | |
// main.swift | |
// CSVToTables | |
// | |
// Created by Christopher Brandow on 7/12/16. | |
// Copyright © 2016 flouu. All rights reserved. | |
// |
NewerOlder