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> | |
@interface NSString (PRHEnumerateMatches) | |
- (NSUInteger) enumerateSubstringsMatchingString_PRH:(NSString *)otherString | |
options:(NSStringCompareOptions)mask | |
usingBlock:(void (^)(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop))block; | |
@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
CATextLayer *crashOMaticLayer = [CATextLayer new]; | |
CGColorRef color = CGColorCreateGenericRGB(1.0, 0.0, 0.0, 1.0); | |
crashOMaticLayer.backgroundColor = color; | |
CGColorRelease(color); | |
crashOMaticLayer.foregroundColor = CGColorGetConstantColor(kCGColorWhite); | |
crashOMaticLayer.string = @"Special Crash-O-Matic Ed."; | |
crashOMaticLayer.alignmentMode = kCAAlignmentCenter; | |
crashOMaticLayer.fontSize = 18.0; | |
//Your coordinates may vary. | |
NSSize size = { 300.0, 20.0 }; |
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
extern NSArray *PRHArrayByMap(NSArray *inArray, id (^block)(id)); |
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
//http://stackoverflow.com/a/20944359/30461 | |
#import <Foundation/Foundation.h> | |
int main(int argc, char *argv[]) { | |
@autoreleasepool { | |
NSString *unicodedString = @"{\\rtf1\\ansi\\ansicpg1252\\cocoartf1265" | |
@"{\\fonttbl\\f0\\fswiss\\fcharset0 Helvetica;\\f1\\fnil\\fcharset0 LucidaGrande;}" | |
@"{\\colortbl;\\red255\\green255\\blue255;}" | |
@"{\\*\\listtable{\\list\\listtemplateid1\\listhybrid{\\listlevel\\levelnfc23\\levelnfcn23\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace360\\levelindent0{\\*\\levelmarker \\{check\\}}{\\leveltext\\leveltemplateid1\\'01\\uc0\\u10003 ;}{\\levelnumbers;}\\fi-360\\li720\\lin720 }{\\listname ;}\\listid1}}" |
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
#!/usr/bin/env python | |
import re | |
keys = [ | |
'.,@1?!*#/\':;', | |
'abc2', | |
'def3', | |
'ghi4', | |
'jkl5', | |
'mno6', |
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> | |
static void test(NSString *str); | |
int main(int argc, char *argv[]) { | |
@autoreleasepool { | |
test(@"mailto:[email protected]"); | |
test(@"mailto:[email protected]?subject=Support%20Request&body=I%20NEED%20HELP%21"); | |
test(@"callto://examplesteve"); | |
test(@"callto:+17145551234"); |
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
/* Let's say you want to list all of the options to your program as an enum */ | |
enum Option { | |
OptionFoo, | |
OptionBar | |
} | |
/* You want to write a procedure to generate a help message for your program. Here's the loopless/countless way: */ | |
int option = OptionFoo; |
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
//So you have an enumeration that counts up to some value. | |
enum { | |
A = 1, | |
B, C, D, E, F, G, H, I, | |
J | |
}; | |
//You may be reading this enum from an input file. You'd like to check whether you have a valid value. | |
//One way would be to have a count value: | |
enum { |
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> | |
/*Usage: | |
*PRH_KVCKey(employer) | |
*PRH_KVCKeyPath(employer, employees, count) | |
*/ | |
#define NDEBUG 1 | |
//A selector that cannot be a valid KVC key, but is a known selector (i.e., the compiler won't warn that it's unknown), and is long enough that its length is probably unique. |
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
Here's a bunch of sample code to drop into your app for free | |
I didn't bother test it, I just puked out a class hastily | |
I might not have even written it, I might've simply Googled it | |
It might not even work at all; the author might have bungled it | |
Explanations are for losers for whom the code alone's not good enough | |
The sort of folks infatuated with things like truly learning stuff | |
This code is what you asked about; is a sample not enough for you? | |
Is understanding the solution really such a thing for you? |