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
Merge Sort | |
Merge sort sebenarnya ya sorting mengurutkan dari kecil ke besar dari besar ke kecil, implementasinya yg disorting itu bisa angka (int, float atau double), bisa juga karakter ASCII atau Unicode. | |
Bedanya sorting di sini menggunakan prinsip divide and conquer atau devide et impera :D | |
Untuk memahami merge sort, perlu pemahaman tentang fungsi rekursif, kalo belom tahu ya belajar dulu tentang rekursif. | |
Ada tiga step penting di merge sort, yaitu: | |
1. Sort setengah bagian kiri dari array. (rekursif) |
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
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { | |
FBRequest *met = [FBRequest requestWithGraphPath:@"/me/feed" parameters:nil HTTPMethod:@"GET"]; | |
[met startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) { | |
// dapetin result | |
}]; | |
}]; |
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
+(CGSize)getLabelSizeWordWrapWithString:(NSString*)string font:(UIFont*)font | |
constrainedToSize:(CGSize)constrainedSize | |
{ | |
if (IOS_VERSION_LESS_THAN_7) { | |
CGSize size = [string sizeWithFont:font | |
constrainedToSize:constrainedSize | |
lineBreakMode:NSLineBreakByWordWrapping]; | |
return size; |
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 a generated tiny UIImage with color | |
// Created not by me. | |
- (UIImage *)imageWithColor:(UIColor *)color | |
{ | |
CGRect rect = CGRectMake(0, 0, 1, 1); | |
// Create a 1 by 1 pixel context | |
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0); | |
[color setFill]; | |
UIRectFill(rect); // Fill it with your color |
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
// Get string time duration from 2 different NSDate object | |
- (NSString *)getNaturalLanguageForDate:(NSDate *)date1 andDate:(NSDate *)date2 withCalendar:(NSCalendar *)sysCalendar | |
{ | |
// Get conversion to months, days, hours, minutes | |
unsigned int unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit; | |
NSDateComponents *breakdownInfo = [sysCalendar components:unitFlags fromDate:date1 toDate:date2 options: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
// Return image Image scaledToFillSize, perfect for thumbnailing | |
// taken from http://stackoverflow.com/a/17884863/1328982 | |
+ (UIImage *)imageWithImage:(UIImage *)image scaledToFillSize:(CGSize)size | |
{ | |
CGFloat scale = MAX(size.width/image.size.width, size.height/image.size.height); | |
CGFloat width = image.size.width * scale; | |
CGFloat height = image.size.height * scale; | |
CGRect imageRect = CGRectMake((size.width - width)/2.0f, | |
(size.height - height)/2.0f, | |
width, |
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
// Print filename and line with comments | |
// credits to Taufik Obet | |
#ifndef __OPTIMIZE__ | |
# define NSLog(...) printf("[%-30s:%4d]: %s\n", __FILE_NAME_ONLY__, __LINE__, [[NSString stringWithFormat:__VA_ARGS__] UTF8String]) | |
#else | |
#define NSLog(...) do {} while (0) | |
#endif |
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
/* | |
Get UILabel's size for wordwrapping style | |
*/ | |
+(CGSize)getLabelSizeWordWrapWithString:(NSString*)string | |
font:(UIFont*)font | |
constrainedToSize:(CGSize)constrainedSize | |
{ | |
if (IOS_VERSION_LESS_THAN_7) { | |
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
// draw circler image | |
-(void)drawClippedAvatar:(UIImage *)image inRect:(CGRect)rect andContext:(CGContextRef)context | |
{ | |
CGMutablePathRef path = CGPathCreateMutable(); | |
CGPathAddEllipseInRect(path, NULL, rect); | |
CGContextAddPath(context, path); | |
CGContextClip(context); | |
CGPathRelease(path); | |
[image drawInRect:rect]; | |
} |
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
#include <iostream> | |
using namespace std; | |
/** | |
User refrence sign '&' to make it pass by refernce. | |
*/ | |
void initString(char* &dest) { | |
dest = new char[255]; | |
dest[0] = 'a'; |
OlderNewer