This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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(); | |
| } | |
| } |
This file contains hidden or 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; | |
| #define ENABLE_LOGGING 1 | |
| #if ENABLE_LOGGING | |
| #define DHLog(__FORMAT__, ...) NSLog((__FORMAT__), ##__VA_ARGS__) | |
| #else | |
| #define DHLog(...) do { } while (0) | |
| #endif |
This file contains hidden or 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; | |
| @implementation NSArray (DHAccumulate) | |
| - (id)dh_objectByReducingWithOptions:(NSEnumerationOptions)options usingBlock:(id (^)(id object1, id object2))reductionBlock | |
| { | |
| if (options & NSEnumerationConcurrent) { | |
| [NSException raise:NSInvalidArgumentException format:@"Bad things will happen if you try to reduce an array concurrently."]; | |
| } | |
This file contains hidden or 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 NSColor (DHLuminance) | |
| - (CGFloat)dh_luminance | |
| { | |
| return 0.3 * [self redComponent] + 0.6 * [self greenComponent] + 0.1 * [self blueComponent]; | |
| } | |
| @end | |
| // Example usage for an attributed string: |