Skip to content

Instantly share code, notes, and snippets.

View achalaggarwal's full-sized avatar
🎯
Focusing

Achal Aggarwal achalaggarwal

🎯
Focusing
View GitHub Profile
@achalaggarwal
achalaggarwal / UIImage+PSPDFKitAdditions.m
Created August 16, 2011 09:32 — forked from steipete/UIImage+PSPDFKitAdditions.m
Preload UIImage for super-smooth interaction. especially great if you use JPGs, which otherwise produce a noticeable lag on the main thread.
- (UIImage *)pspdf_preloadedImage {
CGImageRef image = self.CGImage;
// make a bitmap context of a suitable size to draw to, forcing decode
size_t width = CGImageGetWidth(image);
size_t height = CGImageGetHeight(image);
CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef imageContext = CGBitmapContextCreate(NULL, width, height, 8, width*4, colourSpace,
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little);
@achalaggarwal
achalaggarwal / top3stories.js
Created August 19, 2011 16:00 — forked from DTrejo/top3stories.js
Gets top three articles from frontpage and newpage of Hacker News. Blog post on scraping: http://blog.dtrejo.com/scraping-made-easy-with-jquery-and-selectorga
// Scraping Made Easy with jQuery and SelectorGadget
// (http://blog.dtrejo.com/scraping-made-easy-with-jquery-and-selectorga)
// by David Trejo
//
// Install node.js and npm:
// http://joyeur.com/2010/12/10/installing-node-and-npm/
// Then run
// npm install jsdom jquery http-agent
// node numresults.js
//
@achalaggarwal
achalaggarwal / gist:1200842
Created September 7, 2011 15:16
GCRequest.get()
NSString *_path = [[NSString alloc] init];
GCRequest *gcRequest = [[GCRequest alloc] init];
//Synchronous Request
GCResponse *_response = [[gcRequest getRequestWithPath:_path] retain];
//Asynchronous request
[gcRequest getRequestInBackgroundWithPath:_path withResponse:^(GCResponse *response) {
NSLog(@"%@", response);
@achalaggarwal
achalaggarwal / gist:1200851
Created September 7, 2011 15:22
GCRequest.post()
NSString *_path = [[NSString alloc] init];
NSDictionary *_params = [[NSDictionary alloc] init];
GCRequest *gcRequest = [[GCRequest alloc] init];
//Synchronous Request
GCResponse *_response = [[gcRequest postRequestWithPath:_path andParams:_params] retain];
//Asynchronous request
@achalaggarwal
achalaggarwal / gist:1200861
Created September 7, 2011 15:24
GCRequest.put()
NSString *_path = [[NSString alloc] init];
NSDictionary *_params = [[NSDictionary alloc] init];
GCRequest *gcRequest = [[GCRequest alloc] init];
//Synchronous Request
GCResponse *_response = [[gcRequest putRequestWithPath:_path andParams:_params] retain];
//Asynchronous request
@achalaggarwal
achalaggarwal / gist:1200866
Created September 7, 2011 15:26
GCRequest.delete()
NSString *_path = [[NSString alloc] init];
NSDictionary *_params = [[NSDictionary alloc] init];
GCRequest *gcRequest = [[GCRequest alloc] init];
//Synchronous Request
GCResponse *_response = [[gcRequest deleteRequestWithPath:_path andParams:_params] retain];
//Asynchronous request
@achalaggarwal
achalaggarwal / gist:1200879
Created September 7, 2011 15:31
GCChute.new() and GCChute.save()
GCChute *_newChute = [GCChute new];
[_newChute setName:@"Hello World"];
//Set Permissions for a Chute
[_newChute setPermissionView:GCPermissionTypePublic];
[_newChute setPermissionAddMembers:GCPermissionTypePublic];
[_newChute setPermissionAddPhotos:GCPermissionTypePublic];
[_newChute setPermissionAddComments:GCPermissionTypePublic];
[_newChute setModeratePhotos:GCPermissionTypePublic];
@achalaggarwal
achalaggarwal / gist:1200894
Created September 7, 2011 15:35
GCChute.all()
//Synchronous Request
GCResponse *_response = [GCChute all];
for (GCChute *chute in [_response object]) {
//Individual Chutes
NSLog(@"%@", chute);
}
//Asynchronous Request
[GCChute allInBackgroundWithCompletion:^(GCResponse *response) {
@achalaggarwal
achalaggarwal / gist:1200911
Created September 7, 2011 15:39
GCChute.find(id)
//Synchronous Request
GCResponse *response = [GCChute findById:42];
GCChute *chute = [response object];
//Asynchronous Request
[GCChute findById:42 inBackgroundWithCompletion:^(GCResponse *response) {
GCChute *chute = [response object];
}];
@achalaggarwal
achalaggarwal / gist:1200923
Created September 7, 2011 15:42
GCChute.update()
GCResponse *response = [GCChute findById:29];
GCChute *chute = [response object];
[chute setName:@"NewName"];
//Synchronous Request
if ([chute update]) {
//Updated
}