Skip to content

Instantly share code, notes, and snippets.

View iamleeg's full-sized avatar
New mailing list for software engineering discussion:

Graham Lee iamleeg

New mailing list for software engineering discussion:
View GitHub Profile
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 / 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;
iamleeg /
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 / pileOfPoo.m
Created March 22, 2012 01:51
The pile of poo Objective-C method
#import <Foundation/Foundation.h>
@interface A: NSObject
@implementation A
void pileOfPoo(id self, SEL _cmd) {
iamleeg /
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))) {
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 /
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/");
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" "">
<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; }
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 (/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/
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/
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/
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)