Debounce a function when you want it to execute only once after a defined interval of time. If the event occurs multiple times within the interval, the interval is reset each time.
Example A user is typing into an input field and you want to execute a function, such as a call to the server, only when the user stops typing for a certain interval, such as 500ms.
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
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
// Taken from the commercial iOS PDF framework http://pspdfkit.com. | |
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved. | |
// Licensed under MIT (http://opensource.org/licenses/MIT) | |
// | |
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it. | |
#import <objc/runtime.h> | |
#import <objc/message.h> | |
// Compile-time selector checks. |
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
#import <Mantle.h> | |
@interface BaseModel : MTLModel <MTLJSONSerializing> | |
@property (nonatomic) int64_t id; | |
@property (nonatomic) NSTimeInterval createdUtc; | |
@property (nonatomic) NSTimeInterval modifiedUtc; | |
- (NSString *)createTableStatement; | |
- (NSString *)className; |
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
// Create text attachment | |
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init]; | |
textAttachment.image = [UIImage imageNamed:nameicon]; | |
textAttachment.bounds = CGRectMake(0, 0, 20, 16); | |
// Attribute | |
NSAttributedString *attrStringWithImage = [NSAttributedString attributedStringWithAttachment:textAttachment]; | |
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithAttributedString:attrStringWithImage]; | |
// Change base line |
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
@interface UIImage (Orientation) | |
- (UIImage*)imageByNormalizingOrientation; | |
@end | |
@implementation UIImage (Orientation) | |
- (UIImage*)imageByNormalizingOrientation { |
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
secret = "xxx" | |
data = "http://someurl?someparams" | |
hmac = OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), secret.encode("ASCII"), data.encode("ASCII")) | |
signature = Base64.encode64(hmac).chomp |
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) addNewItemFromArray:(NSArray *) newArrItem | |
{ | |
// Add | |
[_arrPhotos addObjectsFromArray:newArrItem]; | |
NSMutableArray *arrNewIndexpath = [NSMutableArray array]; | |
for (NSInteger i = _arrPhotos.count ; i < _arrPhotos.count + newArrItem.count ; i++) | |
{ | |
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:i inSection:0]; | |
[arrNewIndexpath addObject:newIndexPath]; |
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
__weak FePreviewVideoViewController *weakSelf = self; | |
timeObserver = [_player addPeriodicTimeObserverForInterval:CMTimeMake(15, 1) queue:dispatch_get_main_queue() usingBlock:^(CMTime time) | |
{ | |
typeof(self) strongSelf = weakSelf; | |
CGFloat currentTime = CMTimeGetSeconds(time); | |
if (currentTime >= 15) | |
{ | |
[strongSelf.player pause]; |