Skip to content

Instantly share code, notes, and snippets.

View neilinglis's full-sized avatar

Neil Inglis neilinglis

View GitHub Profile
@neilinglis
neilinglis / gist:e238d5f22f85fa259ade
Created September 16, 2014 08:55
Storyboard Merge Conflict. Is there any sensible course of action for this?
<<<<<<< HEAD
<segue reference="kXa-Mw-CAj"/>
<segue reference="TDo-lS-nUS"/>
<segue reference="hJU-8t-Kde"/>
<segue reference="haI-hu-Unh"/>
<segue reference="2ra-9a-RvO"/>
<segue reference="ixW-dA-JnA"/>
=======
<segue reference="BwM-Nh-uZ9"/>
<segue reference="YWK-Ch-lfU"/>
@neilinglis
neilinglis / gist:5956866
Created July 9, 2013 12:10
NSImage's imageFileTypes
types = (
"'PDF '",
PDF,
pdf,
"'PICT'",
PIC,
pic,
PCT,
pct,
PICT,
NSString *filePathInAssetsFolder = [assetURL.path stringByReplacingOccurrencesOfString:self.managedAssetFolderURL.path withString:@""];
NSString *resolution = @"1x";
//strip out the resolution from the filename and use it to populate the resolutions array
NSRange lastResolutionOccurrence = [filePathInAssetsFolder rangeOfString:@"@" options:NSBackwardsSearch]; //in case they have the resolution in filename more than once
if (lastResolutionOccurrence.location != NSNotFound) {
NSString *extension = [filePathInAssetsFolder pathExtension];
NSString *pathUpToResolutionString = [filePathInAssetsFolder substringToIndex:lastResolutionOccurrence.location];
NSRange extensionLocation = [filePathInAssetsFolder rangeOfString:@"." options:NSBackwardsSearch];
@neilinglis
neilinglis / gist:5032083
Last active October 19, 2020 20:56
I expected that, all other attributes being equal, if I have two identical strings, one with font size twice the other, then NSString's sizeWithAttributes would return height of X for the first string and X*2 for the second. It doesn't. Fonts are weird, yo.
NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraphStyle setAlignment:NSCenterTextAlignment];
[paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
NSFont *font1 = [NSFont fontWithName:@"HelveticaNeue-Medium" size:12];
NSFont *font2 = [NSFont fontWithName:@"HelveticaNeue-Medium" size:24];
NSDictionary *attributes1 = @{NSFontAttributeName : font1, NSParagraphStyleAttributeName : paragraphStyle};
@neilinglis
neilinglis / gist:4260598
Created December 11, 2012 17:50
NSTextAlignment Naming Differences
Am I out of order being annoyed at things like this? The naming has changed subtly, the direction is at the end in UIKit but at the start on AppKit. If I'm writing cross platform code then I need to either use the int values directly, which is bad practice, or use a define.
UIKit:
enum {
NSTextAlignmentLeft = 0,
NSTextAlignmentCenter = 1,
NSTextAlignmentRight = 2,
NSTextAlignmentJustified = 3,
NSTextAlignmentNatural = 4,
@neilinglis
neilinglis / gist:2895424
Created June 8, 2012 12:45
Shoudn't the static analyser catch this?
NSMutableArray *test = [NSMutableArray array];
if (YES) {
NSMutableArray *test = [NSMutableArray array];
[test addObject:@"FOO"];
}
NSLog(@"%ld",(long)[test count]); //0, naturally
@neilinglis
neilinglis / gist:2814861
Created May 27, 2012 15:56
Rough Haversine Formula
#import "CLLocation+NHIAdditions.h"
@implementation CLLocation (NHIAdditions)
- (CGFloat)distanceToPoint:(CLLocation*)pointB
{
//uses the haversine formula. http://en.wikipedia.org/wiki/Haversine_formula
NSInteger nRadius = 6371; // Earth's radius in Kilometers
// Get the difference between our two points then convert the difference into radians
CGFloat differenceInLatitudes = (pointB.coordinate.latitude - self.coordinate.latitude) * (M_PI/180);
@neilinglis
neilinglis / gist:1267913
Created October 6, 2011 16:48
Error When Playing Audio in Simulator (Works on Device)
Error loading /System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn: dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /DeveloperForiOS5/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /System/Library/Frameworks/Security.framework/Versions/A/Security
Error loading /System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn: dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Securit