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
__weak typeof(self) weakSelf = self; |
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
- (NSRange)rangeOfRegularExpressionPattern:(NSString *)pattern inString:(NSString *)string | |
{ | |
NSRegularExpression *expression = [NSRegularExpression regularExpressionWithPattern:pattern options:nil error:nil]; | |
NSTextCheckingResult *result = [expression firstMatchInString:string options:nil range:NSMakeRange(0, [string length])]; | |
return result.range; | |
} |
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
__weak typeof(self) weakSelf = self; |
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)centerViewGroupInY:(NSArray *)views withFixedSpace:(CGFloat)space options:(NSLayoutFormatOptions)options | |
{ | |
if (![views count]) | |
return; | |
NSMutableString *mutableConstraint = [@"V:|[topSpacer(==bottomSpacer)]" mutableCopy]; | |
UIView *topSpacer, *bottomSpacer; | |
NSDictionary *metrics = @{@"space":@(space)}; | |
NSMutableDictionary *viewsMutableDictionary = [NSMutableDictionary dictionary]; | |
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)setImage:(UIImage *)image withCornerRadius:(CGFloat)cornerRadius | |
{ | |
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 1.0); | |
[[UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:cornerRadius] addClip]; | |
[image drawInRect:self.bounds]; | |
self.image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
} |
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
@weakify(self) | |
[[self.firstTextField rac_signalForControlEvents:UIControlEventEditingDidEndOnExit] | |
subscribeNext:^(id x) { | |
@strongify(self) | |
[self.secondTextField becomeFirstResponder]; | |
}]; |
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
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; | |
formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss"; |
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 greatestCommonDivisor(first: Int, second: Int) -> Int { | |
return internalPrivateGreatestCommonDivisor(first, second, min(first, second)) | |
} | |
private func internalPrivateGreatestCommonDivisor(first: Int, second: Int, divider: Int) -> Int { | |
if divider == 0 { | |
return 0 | |
} | |
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
struct HeightedUnion { | |
typealias QuickUnionRootHeight = (root: Int, height: Int) | |
private var ids: [Int] | |
// Complexity: O(n) | |
init(_ N: Int) { | |
ids = Array(0..<N) | |
} |
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 Array where Element: Comparable { | |
// This implementations are inspired in https://github.com/python/cpython/blob/master/Lib/bisect.py | |
/// Return the index where to insert value in the receiver, assuming the receiver is sorted | |
/// | |
/// - Parameters: | |
/// - value: The position of the text in current context | |
/// - min: The lower bound where to perform the search | |
/// - max: The upper bound where to perform the search | |
/// - Returns: An index such that all elements in self[:i] have element < value, and all elements in |
OlderNewer