Skip to content

Instantly share code, notes, and snippets.

@sdpjswl
sdpjswl / Fix video orientation
Created September 28, 2014 10:49
Fix video orientation
-(void)fixOrientationOfVideoAtURL:(NSURL *)videoURL {
AVAsset *firstAsset = [AVAsset assetWithURL:videoURL];
if(firstAsset !=nil && [[firstAsset tracksWithMediaType:AVMediaTypeVideo] count]>0){
//Create AVMutableComposition Object.This object will hold our multiple AVMutableCompositionTrack.
AVMutableComposition* mixComposition = [[AVMutableComposition alloc] init];
//VIDEO TRACK
AVMutableCompositionTrack *firstTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
[firstTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, firstAsset.duration) ofTrack:[[firstAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:kCMTimeZero error:nil];
@sdpjswl
sdpjswl / Header files search path
Created September 28, 2014 10:50
Header files search path
In "Build Settings" ---> "User Headers Search Paths",
$(PROJECT_DIR) ... Recursive
@sdpjswl
sdpjswl / Git commands
Created September 28, 2014 10:51
Git commands
Create a git repo:
git init
Remove a git repo:
cd repository-path/
rm -r .git
Check if directory is under git control:
git rev-parse --is-inside-work-tree
@sdpjswl
sdpjswl / POST method
Created September 28, 2014 10:53
POST method sample code
-(void)firePOSTMethod {
NSString *boundary = @"----WebKitFormBoundarycC4YiaUFwM44F6rT";
// create request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[request setHTTPShouldHandleCookies:NO];
[request setTimeoutInterval:30];
[request setHTTPMethod:@"POST"];
@sdpjswl
sdpjswl / Rotate a UIView
Created September 28, 2014 10:54
Rotate a UIView
// rotate
[UIView animateWithDuration:0.25 animations:^{
CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2);
viewObject.transform = transform;
}];
// back to default position
[UIView animateWithDuration:0.25 animations:^{
CGAffineTransform transform = CGAffineTransformMakeRotation(0);
viewObject.transform = transform;
@sdpjswl
sdpjswl / Take screenshot
Created September 28, 2014 12:18
Take screenshot of a UIView
- (UIImage *)getScreenshot {
UIGraphicsBeginImageContextWithOptions(imageView.frame.size, NO, 0.0);
[viewObject.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *createdImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return createdImage;
}
Replace "viewObject" with the name of the view or image view you want to take a screenshot of.
@sdpjswl
sdpjswl / ScrollView content size
Created September 28, 2014 12:19
Calculate UIScrollView content size
CGRect contentRect = CGRectZero;
for (UIView *view in scrollViewObject.subviews) {
contentRect = CGRectUnion(contentRect, view.frame);
}
scrollViewObject.contentSize = contentRect.size;
@sdpjswl
sdpjswl / Hidden files
Last active August 29, 2015 14:07
Show/hide hidden files on Mac
To show hidden files in Finder, enter the following two commands into a Terminal window (press enter after each line):
defaults write com.apple.Finder AppleShowAllFiles TRUE
killall Finder
To hide hidden files in Finder, enter the following two commands into a Terminal window (press enter after each line):
defaults write com.apple.Finder AppleShowAllFiles FALSE
killall Finder
@sdpjswl
sdpjswl / ScrollView keyboard
Created September 29, 2014 05:27
Adjust ScrollView when keyboard appears
// call "registerForKeyboardNotifications" to enable
- (void)registerForKeyboardNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
}
@sdpjswl
sdpjswl / Custom NavBar title
Last active August 29, 2015 14:07
Custom title color and font on navigation bar
self.navigationItem.title = @"Place Charles De Gaulle";
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], NSForegroundColorAttributeName,
[UIFont fontWithName:@"Roboto-Light" size:21], NSFontAttributeName, nil];