This file contains 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
///Using Foundation. | |
-(void)getWordsFromString:(NSString *)string withFrequency:(NSUInteger)frequency completion:(void(^)(NSArray *array))block { | |
NSDate *date = [NSDate date]; | |
__block NSTimeInterval interval = 0.0; | |
NSMutableDictionary *temp = [NSMutableDictionary dictionaryWithCapacity:1000]; | |
[string enumerateSubstringsInRange:NSMakeRange(0, string.length) options:NSStringEnumerationByWords usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { | |
if(!temp[substring]) { | |
temp[substring] = @1; | |
} | |
else { |
This file contains 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
-(NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext { | |
return .7; | |
} | |
-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext { | |
UIViewController *toController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; | |
UIViewController *fromController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; | |
CGRect finalFrame = [transitionContext finalFrameForViewController:toController]; | |
UIView *containerView = [transitionContext containerView]; |
This file contains 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
module Main where | |
loop :: Integer -> [Integer] -> Integer -> Integer -> [Integer] | |
loop upper list cur prev | |
| (cur == upper) = list ++ [cur] | |
| (cur > upper) = list | |
| otherwise = loop upper (list ++ [cur]) (cur + prev) cur | |
fibSeq :: Integer -> [Integer] | |
fibSeq 0 = [0] | |
fibSeq 1 = [0,1] | |
fibSeq n = loop n [0] 1 0 |
This file contains 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
- (BOOL)isPowerOfTwo:(NSUInteger)number { | |
if(number == 0) return NO; | |
if(number == 1 || number == 2) return YES; | |
return [self findPower:number accumulator:2]; | |
} | |
- (BOOL)findPower:(NSUInteger)n accumulator:(NSUInteger)accumulator { | |
if(accumulator == n) return YES; | |
if(accumulator > n) return NO; | |
return [self findPower:n accumulator:(2 * accumulator)]; |
This file contains 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
#define NSConstraintMake(item, itemAttribute, relation, otherItem, otherAttribute, multiplier, constant) \ | |
[NSLayoutConstraint constraintWithItem:item attribute:itemAttribute relatedBy:relatation toItem:otherItem attribute:otherAttribute multiplier:multiplier constant:constant] \ | |
#define kLeading NSLayoutAttributeLeading | |
#define kTrailing NSLayoutAttributeTrailing | |
#define kTop NSLayoutAttributeTop | |
#define kBottom NSLayoutAttributeBottom | |
#define kCenterX NSLayoutAttributeCenterX | |
#define kCenterY NSLayoutAttributeCenterY | |
#define kLeft NSLayoutAttributeLeft |
This file contains 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
@implementation NSPredicate (CHAdditions) | |
+ (NSPredicate *)sharedValidEmailPredicate { | |
static NSPredicate *_sharedPredicate = nil; | |
static NSString *_emailRegEx = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
_emailRegEx = | |
@"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}" | |
@"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\" | |
@"x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-" |
This file contains 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)saveImages:(NSArray *)images toGroup:(ALAssetsGroup *)group next:(void (^)(NSData *imageData))next error:(void (^)(NSError *))errorBlock completion:(void (^)())block { | |
dispatch_queue_t queue = dispatch_queue_create("com.photoShare.saveToCameraRoll", NULL); | |
[images enumerateObjectsUsingBlock:^(PPSAsset *obj, NSUInteger idx, BOOL *stop) { | |
dispatch_async(queue, ^{ | |
dispatch_semaphore_t sema = dispatch_semaphore_create(0); | |
[self.library writeImageDataToSavedPhotosAlbum:obj.fullImageData metadata:obj.metaData completionBlock:^(NSURL *assetURL, NSError *error) { | |
if(error) { | |
errorBlock(error); | |
} |
This file contains 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
(doseq [xml-content (:content xml)] | |
(spit file-name (:a-key xml-content)) | |
(spit file-name (:another-key xml-content) :append true) | |
) ;;on last pass I need to spit an end marker |
This file contains 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)showVerticallyOnLeftSideOfView:(UIView *)parent havingNavigationBar:(BOOL)havingNavBar { | |
[parent addSubview:self]; | |
CGFloat widthOffset = havingNavBar ? 64 : 0; | |
CGFloat x = CGRectGetWidth(parent.bounds) - (CGRectGetHeight(parent.bounds)); | |
self.frame = (CGRect){ | |
.origin.x = x, | |
.origin.y = CGRectGetMaxY(parent.bounds), | |
.size.width = CGRectGetHeight(parent.bounds) - widthOffset, | |
.size.height = 0 |
This file contains 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
operator infix .. { | |
associativity right | |
} | |
func ..<A, B, C>(f: B -> C, g: A -> B) -> A -> C { | |
return { (a: A) -> C in | |
return f(g(a)) | |
} | |
} |
OlderNewer