This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static NSString * DHStringFromRange(NSRange range); | |
@implementation NSIndexSet (DHDescription) | |
- (NSString *)dh_description | |
{ | |
return [self dh_descriptionShowingRanges:YES]; | |
} | |
- (NSString *)dh_descriptionShowingRanges:(BOOL)shouldShowAsRanges |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
int main(int argc, char *argv[]) { | |
@autoreleasepool { | |
NSCountedSet *set = [NSCountedSet set]; | |
NSError *error; | |
NSString *corpus = [NSString stringWithContentsOfFile:@"some-file.txt" encoding:NSUTF8StringEncoding error:&error]; | |
[corpus enumerateSubstringsInRange:NSMakeRange(0, [corpus length]) options:NSStringEnumerationByWords usingBlock:^(NSString *word, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { | |
[set addObject:word]; | |
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSArray *)dh_preferredLocalizationsFromArray:(NSArray *)requestedLocalisations | |
{ | |
NSMutableSet *possibleLocalisations = [NSMutableSet setWithArray:requestedLocalisations]; | |
BOOL shouldLimitToAvailableLocalisations = YES; // Set to YES to match what NSBundle seems to do, or NO to be more like the documentation. | |
if (shouldLimitToAvailableLocalisations) { | |
[possibleLocalisations intersectSet:[NSSet setWithArray:[[NSBundle mainBundle] localizations]]]; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *DHStringFromFloat(CGFloat value) | |
{ | |
if (value == CGFLOAT_MAX) return @"max"; | |
if (value == CGFLOAT_MIN) return @"min"; | |
return [NSString stringWithFormat:@"%g", value]; | |
} | |
NSString *DHStringFromPoint_bare(CGPoint point) | |
{ | |
return [NSString stringWithFormat:@"%@, %@", DHStringFromFloat(point.x), DHStringFromFloat(point.y)]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// HTMLWriter.swift | |
// Douglas Hill, June 2014 | |
// HTML syntax documentation: http://www.w3.org/TR/html-markup/syntax.html | |
enum HTMLContent { | |
case Element(HTMLElement) | |
case Text(String) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input = "NSHandlesContentAsCompoundValueBindingOption" | |
list = input.split /(?=[A-Z][a-z])/ | |
if list.first.upcase == list.first | |
list.shift | |
end | |
puts list.map {|item| item.downcase}.join " " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface NSObject (DHRecursiveDescription) | |
- (NSString *)dh_recursiveDescriptionWithRecursion:(id (^)(id obj))recursion; | |
@end | |
@implementation NSObject (DHRecursiveDescription) | |
- (NSString *)dh_recursiveDescriptionWithRecursion:(id (^)(id obj))recursion | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation NSArray (DHShortDescription) | |
- (NSString *)dh_oneLineDescription | |
{ | |
return [NSString stringWithFormat:@"[%@]", [self componentsJoinedByString:@", "]]; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
void printInManyEncodings(u_int8_t hex) | |
{ | |
NSData *const data = [NSData dataWithBytes:&hex length:sizeof(hex)]; | |
NSDictionary *const encodings = @{ | |
@"ASCII" : @(NSASCIIStringEncoding), | |
@"NEXTSTEP" : @(NSNEXTSTEPStringEncoding), | |
@"JapaneseEUC" : @(NSJapaneseEUCStringEncoding), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void repeat(NSUInteger repeatCount, void (^blockToRepeat)(void)) | |
{ | |
if (blockToRepeat == nil) { | |
return; | |
} | |
while (repeatCount--) { | |
blockToRepeat(); | |
} | |
} |
OlderNewer