Skip to content

Instantly share code, notes, and snippets.

View steipete's full-sized avatar

Peter Steinberger steipete

View GitHub Profile
@steipete
steipete / gist:2255253
Created March 30, 2012 21:25
ISO 8601 parsing
+ (NSDate *)dateFromISO8601String:(NSString *)iso8601 {
if (!iso8601) {
return nil;
}
const char *str = [iso8601 cStringUsingEncoding:NSUTF8StringEncoding];
char newStr[24];
struct tm tm;
size_t len = strlen(str);
- (void)setActivityCount:(NSInteger)activityCount {
[self willChangeValueForKey:@"activityCount"];
_activityCount = MAX(activityCount, 0);
[self didChangeValueForKey:@"activityCount"];
// some more yada yada from AFNetworking
}
+ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)theKey {
BOOL automatic = NO;
if ([theKey isEqualToString:@"image"]) {
automatic = NO;
} else {
automatic = [super automaticallyNotifiesObserversForKey:theKey];
}
return automatic;
}
- (void) start {
Log(@"Starting %@",self);
[self willChangeValueForKey: @"isExecuting"];
_isExecuting = YES;
[self didChangeValueForKey: @"isExecuting"];
}
- (void) finish {
[self willChangeValueForKey: @"isExecuting"];
[self willChangeValueForKey: @"isFinished"];
- (BOOL)isNetworkActivityIndicatorVisible {
return _activityCount > 0;
}
- (void)incrementActivityCount {
[self willChangeValueForKey:@"activityCount"];
OSAtomicIncrement32((int32_t*)&_activityCount);
[self didChangeValueForKey:@"activityCount"];
}
@steipete
steipete / SafariCache-Proper.sql
Created April 11, 2012 03:01 — forked from alaborie/SafariCache-Proper.sql
Schema of the database used by Safari to cache URL request.
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE cfurl_cache_schema_version(schema_version INTEGER);
CREATE TABLE cfurl_cache_response(entry_ID INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, version INTEGER, hash_value INTEGER, storage_policy INTEGER, request_key TEXT UNIQUE, time_stamp NOT NULL DEFAULT CURRENT_TIMESTAMP);
CREATE TABLE cfurl_cache_blob_data(entry_ID INTEGER PRIMARY KEY, response_object BLOB, request_object BLOB, proto_props BLOB, user_info BLOB);
CREATE TABLE cfurl_cache_receiver_data(entry_ID INTEGER PRIMARY KEY, receiver_data BLOB);
DELETE FROM sqlite_sequence;
CREATE INDEX request_key_index ON cfurl_cache_response(request_key);
CREATE INDEX time_stamp_index ON cfurl_cache_response(time_stamp);
CREATE INDEX proto_props_index ON cfurl_cache_blob_data(entry_ID);
// changes the default implementation in AFURLConnectionOperation to NOT cache per default, unless a block is set.
// we assume that downloads shouln't be saved into NSURLCache (which uses a disk-cache since iOS5)
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection
willCacheResponse:(NSCachedURLResponse *)cachedResponse
{
if (self.cacheResponse) {
return self.cacheResponse(connection, cachedResponse);
} else {
return nil;
}
typedef enum {
YLPDFImageSizeOriginal,
YLPDFImageSizeThumbnail,
YLPDFImageSizeSmall
} YLPDFImageSize;
@class YLDocument;
@protocol YLCacheDelegate <NSObject>
- (void)didCacheDocument:(YLDocument *)document page:(NSUInteger)page size:(YLPDFImageSize)size image:(UIImage *)image;
@steipete
steipete / IPInsetLabel.h
Created May 4, 2012 19:21
IPInsetLabel: a simple UILabel subclass that adds padding insets and auto-height-resizing
//
// IPInsetLabel.h
// Instapaper
//
// Created by Marco Arment on 7/23/11.
// Copyright 2011 Instapaper LLC, released to the public domain.
//
#import <UIKit/UIKit.h>
fatal error: file '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h' has been modified since the precompiled header was built