Skip to content

Instantly share code, notes, and snippets.

View iamleeg's full-sized avatar
📬
New mailing list for software engineering discussion: https://sicpers.curated.co

Graham Lee iamleeg

📬
New mailing list for software engineering discussion: https://sicpers.curated.co
View GitHub Profile
@iamleeg
iamleeg / gist:1466859
Created December 12, 2011 12:09
Using Eero from Xcode 4

Use this as the "custom script" for a build rule for files matching *.ero:

/path/to/clang-eero-prebeta/bin/clang -S -o ${DERIVED_FILES_DIR}/${INPUT_FILE_BASE}.s ${INPUT_FILE_PATH}

The output file should be $(DERIVED_FILES_DIR)/$(INPUT_FILE_BASE).s. Xcode automatically assembles and links the output into the binary.

@iamleeg
iamleeg / FZAUIElement.m
Created December 20, 2011 21:04
Use one selector to provide many methods with similar implementations.
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface FZAUIElement : NSObject
- (id)initWithAXUIElement: (AXUIElementRef)anElement;
- (BOOL)press: (NSError *__autoreleasing*)error;
- (BOOL)cancel: (NSError *__autoreleasing*)error;
@end
@iamleeg
iamleeg / README.md
Created February 3, 2012 18:16
Causing methods generated by AppCode to throw exceptions

Go to "File Templates" in the Preferences window, then under the 'code' tab choose "OC implemented method body" and paste the template method in there. This then causes AppCode to generate methods like this:

- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
    [[NSException exceptionWithName:NSInternalInconsistencyException reason:@"Unimplemented method" userInfo:nil] raise];
    return 0;
    //To change the template use AppCode | Preferences | File Templates.
    
}

Another approach would be to use the usual forwarding approach by putting this as the first line:

@iamleeg
iamleeg / pileOfPoo.m
Created March 22, 2012 01:51
The pile of poo Objective-C method
#import <Foundation/Foundation.h>
@interface A: NSObject
@end
@implementation A
void pileOfPoo(id self, SEL _cmd) {
NSLog(@"💩");
}
@iamleeg
iamleeg / main.mm
Created March 24, 2012 00:23
Using operator overloading with Objective-C. Erm, ++.
#include "objc_id.hpp"
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSString *s1 = @"hello";
NSString *s2 = [@"hell" stringByAppendingString: @"o"];
if ((objc_id(s1) == objc_id(s2))) {
NSLog(@"win");
@iamleeg
iamleeg / gist:2214389
Created March 27, 2012 09:34
Nested C array
int main(int argc, char *argv[]) {
int x[5][5][5];
int i, j, k;
for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++) {
for (k = 0; k < 5; k++) {
x[i][j][k] = k + 5 * j + (5*5*i);
}
}
}
@iamleeg
iamleeg / printplist.pl
Created May 12, 2012 13:39
Using the PerlObjCBridge to display a plist file
#!/usr/bin/perl -w
use strict;
use Foundation;
my $plist = NSDictionary->dictionaryWithContentsOfFile_("/Applications/TextEdit.app/Contents/Info.plist");
print $plist->description()->UTF8String();
Undefined symbols for architecture x86_64:
"_Printf", referenced from:
_main in ccFkWgAM.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
$ vulcan build -c "PREFIX=/opt/libobjc2; mkdir $PREFIX; make" -p /opt/libobjc2 -v -o "$TMPDIR/libobjc2.tgz"
Packaging local directory... done
Uploading source package... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<style type="text/css">
html, body, iframe { margin: 0; padding: 0; height: 100%; }
iframe { display: block; width: 100%; border: none; }
</style>
2012-11-10T14:04:50+00:00 heroku[web.1]: Starting process with command `bin/web`
2012-11-10T14:04:52+00:00 app[web.1]: at Object.run (/app/node_modules/coffee-script/lib/coffee-script/coffee-script.js:79:25)
2012-11-10T14:04:52+00:00 app[web.1]: at Object.<anonymous> (/app/web.coffee:22:28)
2012-11-10T14:04:52+00:00 app[web.1]: at /app/node_modules/coffee-script/lib/coffee-script/command.js:175:29
2012-11-10T14:04:52+00:00 app[web.1]: at Object.<anonymous> (/app/web.coffee:121:4)
2012-11-10T14:04:52+00:00 app[web.1]: at Object.urlParse [as parse] (url.js:92:11)
2012-11-10T14:04:52+00:00 app[web.1]: at Module._compile (module.js:446:26)
2012-11-10T14:04:52+00:00 app[web.1]: at Object.connect (/app/lib/cloudant.coffee:10:22)
2012-11-10T14:04:52+00:00 app[web.1]: TypeError: Parameter 'url' must be a string, not undefined
2012-11-10T14:04:52+00:00 app[web.1]: at [object Object].emit (events.js:64:17)