Skip to content

Instantly share code, notes, and snippets.

View pokeb's full-sized avatar

Ben Copsey pokeb

View GitHub Profile
@pokeb
pokeb / gist:159641
Created August 1, 2009 11:17
Rough example showing download bandwidth throttling with ASIHTTPRequest
- (void)handleBytesAvailable
{
if (![self responseHeaders]) {
if ([self readResponseHeadersReturningAuthenticationFailure]) {
[self attemptToApplyCredentialsAndResume];
return;
}
}
if ([self needsRedirect]) {
- (void)demonstrateCustomBinaryDataParsing
{
// Generate data in the format:
// name:size\n<data>name:size\n<data>
NSData *file1data = [NSData dataWithContentsOfFile:@"/Users/ben/Desktop/1.png"];
NSData *file2data = [NSData dataWithContentsOfFile:@"/Users/ben/Desktop/2.png"];
NSMutableData *payload = [NSMutableData data];
NSLog([NSString stringWithFormat:@"file1:%lu\n",[file1data length]]);
[payload appendData:[[NSString stringWithFormat:@"file1:%lu\n",[file1data length]] dataUsingEncoding:NSASCIIStringEncoding]];
//
// ASIHTTPRequest.m
//
// Created by Ben Copsey on 04/10/2007.
// Copyright 2007-2010 All-Seeing Interactive. All rights reserved.
//
// A guide to the main features is available at:
// http://allseeing-i.com/ASIHTTPRequest
//
// Portions are based on the ImageClient example from Apple:
@pokeb
pokeb / gist:150447
Created July 20, 2009 17:03
An example showing how to manage a queue with ASIHTTPRequest
//
// MyController.h
//
// Created by Ben Copsey on 20/07/2009.
// Copyright 2009 All-Seeing Interactive. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <GHUnit/GHUnit.h>
@class ASINetworkQueue;
@pokeb
pokeb / HTTP Cookie header parser
Created September 13, 2008 11:23
Quick and dirty HTTP cookie header parser in PHP