Skip to content

Instantly share code, notes, and snippets.

@rais38
rais38 / gist:4683817
Last active October 13, 2020 17:36
Embed YouTube videos with UIWebView
#pragma mark - Embed Video
- (UIWebView *)embedVideoYoutubeWithURL:(NSString *)urlString andFrame:(CGRect)frame {
NSString *videoID = [self extractYoutubeVideoID:urlString];
NSString *embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
@rais38
rais38 / gist:4690587
Last active December 12, 2015 01:19
Resize UIImage
/**
@see http://stackoverflow.com/questions/3889687/how-to-compress-an-image-taken-by-the-camera-in-iphone-sdk
UIImage *image = [self scaleImage:myImage toSize:CGSizeMake(320.0,480.0)];
*/
-(UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)newSize {
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
@rais38
rais38 / gist:4690624
Created February 1, 2013 10:51
Calculate the region needed to show a number of POIs in MKMapView
/**
MKCoordinateRegion viewRegion = [self RegionForAnnotations:_arrayPois];
[_mapView setRegion:viewRegion animated:YES];
*/
- (MKCoordinateRegion)RegionForAnnotations:(NSArray *)records {
MKCoordinateRegion region;
// center the map arround our records
// @see https://devforums.apple.com/message/48525#48525
@rais38
rais38 / gist:4730084
Last active December 12, 2015 06:38
UIView with rounded corners
/**
@see http://www.dbsnippets.com/2012/09/11/objective-c-redondear-esquinas-de-un-uiview/
You must import basic Core Animation classes
#import <QuartzCore/QuartzCore.h>
Example:
[self roundView:backgroundColorView onCorner:(UIRectCornerAllCorners) radius:10.0];
[self roundView:imgView onCorner:(UIRectCornerTopLeft|UIRectCornerBottomLeft) radius:5.0];
*/
@rais38
rais38 / gist:4758465
Last active December 12, 2015 10:19
Detect If Your Application Is Running In The Debugger
static bool debuggerRunning(void) {
int junk;
int mib[4];
struct kinfo_proc info;
size_t size;
info.kp_proc.p_flag = 0;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
@rais38
rais38 / gist:5661946
Last active January 5, 2021 16:30
On Mac OS X (LaunchServices and UTIs) to convert a file path to the file's MIME type using.
+ (NSString *)MIMETypeForFileAtPath:(NSString *)path defaultMIMEType:(NSString *)defaultType
{
NSString *result = defaultType;
NSString *extension = [path pathExtension];
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,
(CFStringRef)extension,
NULL);
if (uti) {
CFStringRef cfMIMEType = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType);
if (cfMIMEType) {
@rais38
rais38 / gist:5766980
Created June 12, 2013 16:35
Create patch from stash
git stash show -p stash@{0} > Stash0.patch
__weak typeof(self) weakSelf = self;
@rais38
rais38 / gist:7038167
Created October 18, 2013 08:12
Reveal
#pragma mark - Reveal
#import <dlfcn.h>
- (void)startReveal
{
NSString *revealLibName = @"libReveal";
NSString *revealLibExtension = @"dylib";
NSString *dyLibPath = [[NSBundle mainBundle] pathForResource:revealLibName ofType:revealLibExtension];
NSLog(@"Loading dynamic library: %@", dyLibPath);
void *revealLib = NULL;
@rais38
rais38 / gist:7170792
Created October 26, 2013 15:35
Add gradient animation
- (void)addGradientAnimation
{
UIColor *color1 = [UIColor redColor];
UIColor *color2 = [UIColor yellowColor];
UIColor *color3 = [UIColor grayColor];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.view.frame;
gradient.colors = @[(id)color1.CGColor, (id)color2.CGColor, (id)color2.CGColor];