Skip to content

Instantly share code, notes, and snippets.

View quellish's full-sized avatar

Dan quellish

View GitHub Profile
@quellish
quellish / testDaysSinceSignificantDateCrossingDaylightSavingsChange.m
Created January 23, 2016 21:46
testDaysSinceSignificantDateCrossingDaylightSavingsChange
- (void) testDaysSinceSignificantDateCrossingDaylightSavingsChange {
SignificantEvent *testEvent = nil;
NSInteger expectedResult = 2;
NSInteger testResult = 0;
NSDate *preDaylightSavingsDate = nil;
NSDate *postDaylightSavingsDate= nil;
NSCalendar *calendar = [self testCalendar];
preDaylightSavingsDate = [calendar dateWithEra:1 year:2015 month:3 day:7 hour:12 minute:0 second:0 nanosecond:0];
@quellish
quellish / SignificantEventTests.m
Created January 23, 2016 21:45
SignificantEventTests
@interface PreDaylightSavingsEvent : SignificantEvent
@property (nonatomic, readwrite, copy) NSDate *currentDate;
@end
@implementation PreDaylightSavingsEvent
@synthesize currentDate = _currentDate;
@end
@quellish
quellish / numberOfDaysInThePast2.m
Created January 23, 2016 21:43
numberOfDaysInThePast2
- (NSDate *) currentDate {
return [NSDate date];
}
- (NSInteger) numberOfDaysInThePast{
NSInteger result = 0;
NSDate *now = [self currentDate];
NSTimeInterval diff = 0;
diff = [now timeIntervalSinceDate:[self eventDate]];
@quellish
quellish / numberOfDaysInThePast.m
Created January 23, 2016 21:42
numberOfDaysInThePast
- (NSInteger) numberOfDaysInThePast{
NSInteger result = 0;
NSDate *now = [NSDate date];
NSTimeInterval diff = 0;
diff = [now timeIntervalSinceDate:[self eventDate]];
result = diff / (24 * 60 * 60);
return result;
}
@quellish
quellish / SignificantEvent.h
Created January 23, 2016 21:41
SignificantEvent
@interface SignificantEvent : NSObject
@property (nonatomic, readonly, copy) NSDate *eventDate;
- (instancetype) initWithEventDate:(NSDate *)eventDate;
@end
@interface SignificantEvent (DaysSince)
- (NSInteger) numberOfDaysInThePast;
@quellish
quellish / retry-after.m
Created October 9, 2015 21:02
Retry-After iOS workaround
id retryAfterValue = [[(NSHTTPURLResponse *)response allHeaderFields] valueForKey:@"Retry-After"];
if (retryAfterValue != nil){
NSMutableDictionary *editedHeaders = [NSMutableDictionary dictionaryWithDictionary:[(NSHTTPURLResponse *)response allHeaderFields]];
// Max-age should be calculated based on the retry-after value, which can be an integer or a string date
NSString *maxAgeString = [NSString stringWithFormat:@"max-age=%@" , retryAfterValue];
[editedHeaders setValue:maxAgeString forKey:@"Cache-Control"];
// Retry-after header must be removed
[editedHeaders setValue:nil forKey:@"Retry-After"];
NSHTTPURLResponse *editedResponse = [[NSHTTPURLResponse alloc] initWithURL:[response URL] statusCode:[(NSHTTPURLResponse *)response statusCode] HTTPVersion:(NSString *)kCFHTTPVersion1_1 headerFields:[editedHeaders copy]];
NSCachedURLResponse *cachedResponse = [[NSCachedURLResponse alloc] initWithResponse
@quellish
quellish / FBClasses.txt
Created August 15, 2015 01:50
Facebook iOS App Class List
headers:
_ASAsyncTransaction.h
_ASAsyncTransactionGroup.h
_ASDisabledPanUITextView.h
_ASDisplayLayer.h
_ASDisplayLayerDelegate-Protocol.h
_ASDisplayView.h
_ASImageNodeDrawParameters.h
_ASPendingState.h
_ASTextNodeCachedMetrics.h
@quellish
quellish / bs.sh
Last active August 29, 2015 14:15
Project build settings
xcodebuild test -configuration Debug -dry-run -showBuildSettings -sdk iphonesimulator
@quellish
quellish / employee.json
Created February 2, 2015 01:02
Data URI Json Example
{
"firstName": "John",
"lastName": "Bigboote",
"href": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAcCAMAAAA3HE0QAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAMBQTFRFNjEvuYqJbVNMSEQ8tLK1xZeWJxsaYmZrjYqOBgQE29bUGRcXnHl1c11XqHV1SjMrh2pkSklAeHh4XUlDy8fGUT0yQDo4VlhZRiwkr4OCpIF9NSAaXWJmbmlpkXd2lWhnZWpwWEQ3flZUUlBLDgoJUDcsmZih39vYGxAOW19gjXJqPyQdgHx+aW90eHNvwr+9YV5ac3B0gGFclHJu2NPQ0s3MZWNiEhAQcXJvmV1i5ODd+Pn4goKGZ0I/qqWpnpaWwhvcSwAAApVJREFUeNpM0tmWojAQBuBiMYhBAREE4gKyqVHRoKA9gu//VlPp7jNngJML6qsfKgB5RzugZk4gTVO/wDNV1en6+XxeLpf28AZKOwn2tl+EfmGHjBcpmmuWXS8uBBpgneLCfJ+zkDPG/TRkRRq4T/1P2cEBOpMSoPswtJntc87Vo6Mybtt5Tp4tpRkQ0wQgrAh5uFPVnbBiy/EwyzTzIAB2giw3O0p9O+S9Zc1iRYliR2BUZ5okC54DjPdoWcF46ESRokjQHFXCMdl0tbcOOsEIKNi+sCJlNBopSrzZCMKgw+myTwU1AgohIXbzDZBYxykhWgAQtPoD7mDmHdiM2c4viNUitCUINHeuQ3UxKWUFx3dQRkrciJ5gmg+ahvXspsPiQzoCNufM8/yQ8J0qiunUCyXI2vIB9SfA12Gc7fdgE1so25Hai6mvaRgwryu4V+McJ+pfYRpFu91WzEazXoj0Byy+YDJZEDM3d7Ndb8l9GClR1PdTLOP1XFQI7kFHc/6Kts1MzhE1jiqE5rqu5q7rCYKqJpSSXlFwqzEjiizhCV+ToNXvCC
@quellish
quellish / NSURLResponse+QUELL_IANACharacterSetEncoding.m
Last active August 29, 2015 14:14
Get the correct string encoding from an NSURLResponse
@interface NSURLResponse(QUELL_IANACharacterSetEncoding)
- (NSStringEncoding) QUELL_stringEncoding;
@end
@implementation NSURLResponse(QUELL_IANACharacterSetEncoding)
- (NSStringEncoding) QUELL_stringEncoding {
NSStringEncoding result = [NSString defaultCStringEncoding];
CFStringEncoding cfEncoding = CFStringGetSystemEncoding();
NSString *ianaCharSetName = [self textEncodingName];