Skip to content

Instantly share code, notes, and snippets.

View pilky's full-sized avatar

Martin Pilkington pilky

View GitHub Profile
@pilky
pilky / gist:998776
Created May 30, 2011 11:46
Example Accessor
- (NSArray *)importsForClass:(Class)aClass {
NSMutableDictionary *importsDict = [NSMutableDictionary dictionary];
for (NSString *identifier in [identifiers objectForKey:aClass]) {
[importsDict addEntriesFromDictionary:[imports objectForKey:identifier]];
}
[importsDict addEntriesFromDictionary:[imports objectForKey:aClass]];
return [importsDict allValues];
}
- If something has an underscore it is classed as private and ignored
- If a typedef appears multiple times (eg in an #if statement) the first documented one is used
- Enums that have both a type def and a name (@enum name) will have the title "type - doc name"
- Any functions or macros found will be placed in a separate functions page
- Constants groups and typedefs in separate files can be related to a class with (@class name). They can have multiple @class statements
- Any constants groups or typedefs found in files that don't contain classes and aren't that related to classes are put in separate constants and data types pages
@pilky
pilky / ShowDerivedData.rb
Created November 5, 2011 14:24
A script for showing the derived data folder for an Xcode workspace. Intended to be invoked from a custom behaviour
#!/usr/bin/env ruby
#This script currently only works if you have your derived data in the default location
#First look for a project path as our workspace
xcodeWorkspacePath = ENV['XcodeProjectPath']
if xcodeWorkspacePath
workspaceName = /([\w\s]+).xcodeproj/.match(xcodeWorkspacePath)[1]
#If we don't have a project we have a workspace, check for that and exit with code 1 if that doesn't exist
else
- (void)method1:(id)somethingElse {
NSString *identifier = [NSString stringWithFormat:@"%@.%@", [SomeClass someMethod], somethingElse];
MyObject *obj = [[MyObject alloc] initWithIdentifier:identifier];
}
- (void)method2:(id)somethingElse {
NSString *identifier = [NSString stringWithFormat:@"%@.%@", [SomeOtherClass someOtherMethod], somethingElse];
MyObject *obj = [[MyObject alloc] initWithIdentifier:identifier];
- (void)performLayout
{
[super performLayout];
myScrubView.frame = self.bounds;
BOOL reload = NO;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait)
{
- (void)sendDetails {
if ([self _shouldShowPrompt]) {
[permissionPromptController showWindow:self];
} else {
[submitter submitDetails];
}
}
- (BOOL)_shouldShowPrompt {
- (void)submitDetails {
//If the user said not to send, don't
if (![[NSUserDefaults standardUserDefaults] boolForKey:TWSSendSystemProfile])
return;
//Generate our last sent check and see if it is different to the stored one
NSString *lastSent = [[NSDate date] descriptionWithCalendarFormat:@"%Y%m" timeZone:[NSTimeZone timeZoneForSecondsFromGMT:0] locale:nil];
if ([lastSent isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:TWSLastSent]])
return;
@pilky
pilky / gist:2425052
Created April 20, 2012 00:37
This is a script that will calculate the number of subsets possible in a set of a given size
def fac(n, limit)
if n == 1
return 1
end
if n == limit
return limit
end
return n * fac(n - 1, limit)
end
@pilky
pilky / gist:2864689
Created June 3, 2012 19:17
Reactive Cocoa example with subscripting hack
Basically I can turn this:
[[[[loginResult
where:^(id x) {
return [x hasError];
}]
select:^(id x) {
return [x error];
}]
injectObjectWeakly:self]
@pilky
pilky / gist:3609846
Created September 3, 2012 14:51
NSLayoutConstraint code, done right
//Pass in arrays of views and access with number keys or add attributes for all
NSArray *views = @[ topView, middleView, lastView ];
[containerView setSubviews:views];
[containerView m3_addConstraints:@[
@"$1.top = 0",
@"$2.top = $1.bottom",
@"$3.top = $2.bottom",
@"$3.bottom = 0",
@"$all.(left, right) = (0, 10)", //Assign multiple attributes in one statement
@"$all.height >= 30"