Skip to content

Instantly share code, notes, and snippets.

View drewmccormack's full-sized avatar

Drew McCormack drewmccormack

View GitHub Profile
@drewmccormack
drewmccormack / gist:5262375
Created March 28, 2013 11:03
A category method for NSArray that facilitates enumeration with regular draining of the autorelease pool. Useful for those long, memory accumulating loops.
@implementation NSArray (AutoreleasePoolDraining)
-(void)enumerateObjectsDrainingEveryIterations:(NSUInteger)iterationsBetweenDrains usingBlock:(void (^)(id object, NSUInteger index, BOOL *stop))block
{
NSUInteger total = 0;
NSUInteger count = self.count;
NSUInteger numberOfChunks = (count / MAX(1,iterationsBetweenDrains) + 1);
BOOL stop = NO;
for ( NSUInteger chunk = 0; chunk < numberOfChunks; chunk++ ) {
@autoreleasepool {
@drewmccormack
drewmccormack / NSString+MCHTMLToPlainTextConversion.h
Created October 5, 2012 14:29
Convert a NSString with HTML into a plain text string using NSXMLParser.
#import <Foundation/Foundation.h>
@interface NSString (MCHTMLToPlainTextConversion)
-(NSString *)stringByConvertingHTMLToPlainText;
@end
@drewmccormack
drewmccormack / MCURLExtensions.m
Created July 14, 2011 13:05
NSURL category method to get the UTI of a file
@implementation NSURL (MCExtensions)
-(NSString *)UTI
{
FSRef fileRef;
Boolean isDirectory;
NSString *utiString = nil;
if ( !self.isFileURL ) return nil;
@drewmccormack
drewmccormack / prefixer.py
Created May 10, 2011 07:25
Change the prefix of a Cocoa project
#!/usr/bin/env python
#---------
# Script to change the prefix of a framework
#---------
import os
import re
import string