Skip to content

Instantly share code, notes, and snippets.

View 0x8badf00d's full-sized avatar

0x8badf00d 0x8badf00d

View GitHub Profile
@0x8badf00d
0x8badf00d / CommonMacros.h
Created January 30, 2012 13:03 — forked from Abizern/CommonMacros.h
Common Macros for Xcode projects
// Useful Macros.
// See http://www.cimgf.com/2010/05/02/my-current-prefix-pch-file/ for details.
#ifdef DEBUG
#define DLog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
#define ALog(...) [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] lineNumber:__LINE__ description:__VA_ARGS__]
#else
#define DLog(...) do { } while (0)
#ifndef NS_BLOCK_ASSERTIONS
#define NS_BLOCK_ASSERTIONS
@0x8badf00d
0x8badf00d / max_nsurlconnections
Created January 30, 2012 20:55
Maximum simultaneous NSURLConnections
When connecting to a public HTTP server, a client should not maintain more
than two open connections to that server at one time. (RFC2616 §8.1.4) An
HTTP server is likely to impose its own limit on the number of simultaneous
connections from a single IP address anyway. Furthermore opening a large
number of simultaneous connections to a server may be seen as a denial of
service (DOS) attack upon the server.
Queuing HTTP 1.1 requests on a single, asynchronous connection such as
NSURLConnection is likely to offer the best throughput anyway - since both
the requests and the responses can be "pipelined" (sent back to back without
[UIView animateWithDuration:1.5f
delay:0.0f
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[self.buttonsView removeFromSuperview];
[self.view addSubview:self.textFieldView];
}
completion:^(BOOL finish){NSLog(@"Finished Bool:%@",finish?@"Yes":@"No");}];
[UIView transitionWithView:self.buttonsView duration:0.7f options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
[self.buttonsView removeFromSuperview],
[self.view addSubview:self.textFieldView];
} completion:^(BOOL finished){ NSLog(@"Finished animation bool: %@",finished?@"YES":@"NO");}];
@0x8badf00d
0x8badf00d / Flip Animation
Created February 1, 2012 00:34
Flip Animation
/// Written by Abizern
[UIView transitionWithView:self.view.superview duration:0.35f options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
UIView *containerView = self.view.superview;
AnalogueView *analogueView = timeViewController.analogueView;
[self.view removeFromSuperview];
[containerView addSubview:analogueView];
}completion:NULL];
[UIView transitionWithView:containerView duration:0.35f options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
@0x8badf00d
0x8badf00d / NSURLConnection
Created February 1, 2012 11:37
NSURLConnection
-(void) downloadAndParse
{
NSURL *nsurl = [[[NSURL alloc] initWithString:@"http://10.230.148.253:8080/IDP/services/login/authuser"] autorelease];
NSMutableURLRequest* urlRequest = [[[NSMutableURLRequest alloc] initWithURL:nsurl] autorelease];
NSURLConnection* conn = [NSURLConnection connectionWithRequest:urlRequest delegate:self];
if(conn)
{
// Declare an iVar NSMutableData* responseData
responseData = [[NSMutableData alloc] init];
}
@0x8badf00d
0x8badf00d / gist:1876181
Created February 21, 2012 12:15
setter
- (void)setValue:(NSString *)aValue
{
if (value != aValue)
{
[value release];
value = [aValue retain];
}
}
@0x8badf00d
0x8badf00d / DownloadOperation.h
Created April 2, 2012 22:25 — forked from zoul/DownloadOperation.h
Asynchronous NSURLConnection in concurrent NSOperation
@interface DownloadOperation : NSOperation
{
NSURLRequest *request;
NSURLConnection *connection;
NSMutableData *receivedData;
}
@property(readonly) BOOL isExecuting;
@property(readonly) BOOL isFinished;
#import <UIKit/UIKit.h>
@interface UIButton (UIButton_BackgroundImageAdditions)
-(void) setBackgroundImageWithColor: (UIColor *) color
cornerRadius: (CGFloat) cornerRadius
forState: (UIControlState) state;
@end
@0x8badf00d
0x8badf00d / NSNotificationCenter+ObserverAdditions.h
Created September 14, 2012 04:02
NSNotificationCenter+ObserverAdditions
#import <Foundation/Foundation.h>
@interface NSNotificationCenter (ObserverAdditions)
- (void)registerObserver:(id)observer
forName:(NSString *)name
object:(id)obj
queue:(NSOperationQueue *)queue
usingBlock:(void (^)(NSNotification *note))block;