Skip to content

Instantly share code, notes, and snippets.

@ddribin
ddribin / gist:380346
Created April 27, 2010 05:15
goto, no macro
- (BOOL)play:(NSError **)error;
{
NSAssert(_graph == NULL, @"Graph is already started");
OSStatus status;
status = NewAUGraph(&_graph);
if (status != noErr)
goto failed;
@ddribin
ddribin / gist:380344
Created April 27, 2010 05:04
goto + macro
#define FAIL_ON_ERR(_X_) if ((status = (_X_)) != noErr) { goto failed; }
- (BOOL)play:(NSError **)error;
{
NSAssert(_graph == NULL, @"Graph is already started");
OSStatus status;
FAIL_ON_ERR(NewAUGraph(&_graph));
FAIL_ON_ERR([self addOutputNode]);
#!/bin/sh
export DEVELOPER_DIR=/Developer
xcode_build="${DEVELOPER_DIR}/usr/bin/xcodebuild"
"$xcode_build" -version
% where python
/usr/bin/python
% python --version
Python 2.6.1
% python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for p in sys.path:
- (NSArray *)arrayForReading
{
NSArray * array;
@synchronized (self) {
array = [[_array retain] autorelease];
}
return array;
}
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len
typedef struct
{
char * file;
int line;
} DDFileContext;
#define DDCurrentFileContext() ((DDFileContext) { .file = __FILE__, .line = __LINE__})
@protocol DDAsyncTaskDelegate <NSObject>
- (void)setResult:(id)result;
- (void)setError:(NSError *)error;
@end
@protocol DDAsyncTask <NSObject>
- (void)startWithDelegate:(id<DDAsyncTaskDelegate>)delegate;
@end
id<DDFuture> DDStartAsyncTask(id<DDAsyncTask> asyncTask);
{
NSOperationQueue * queue = [[[NSOperationQueue alloc] init] autorelease];
NSURL * url = [NSURL URLWithString:@"http://www.example.com/"];
id<DDFuture> futureData = [queue dd_submitCallableBlock:^id (NSError **error) {
NSData * data = [NSData dataWithContentsOfURL:url options:0 error:error];
return data;
}];
// This blocks for the result
- (void) connectUsingBlock:(void (^)(BOOL success, NSError *error))block {
block = [block copy];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),^(void){
NSError *err = nil;
BOOL success = YES;
dispatch_async(dispatch_get_main_queue(),^ {
block(success, err);
// Objective-C equivalent of Ruby's OptionParser
// http://ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html
[optionsParser on:@"-b" :@"--block ARG" :@"Set block arg" :^(id argument) {
NSLog(@"arg: %@", argument);
}];