Skip to content

Instantly share code, notes, and snippets.

View simonpang's full-sized avatar

Simon Pang simonpang

  • Hong Kong
View GitHub Profile
@simonpang
simonpang / gist:3383699
Created August 18, 2012 00:50
Rubymotion build time use cases
Simons-MacBook-Air:ruby simon$ git clone https://github.com/siuying/motion-github-followers
Testing Environment
====================
* OS X 10.8
* Xcode 4.4
* 1.6Ghz Core i5 (MBA 11", Mid 2011)
* 4GB memory
@simonpang
simonpang / gist:3754248
Created September 20, 2012 06:22
Upload photo to server
#pragma mark DLCImagePickerControllerDelegate
-(void) imagePickerControllerDidCancel:(DLCImagePickerController *)picker{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:NO];
[self dismissModalViewControllerAnimated:YES];
}
- (void)uploadMediaInfo:(NSDictionary *)info {
UIImage *resizedImage = [[info objectForKey:@"image"] imageCroppedToFitSize:CGSizeMake(800, 800)];
NSData *jpegData = UIImageJPEGRepresentation(resizedImage, 0.5);
@simonpang
simonpang / gist:3754256
Created September 20, 2012 06:26
Debug network connections using AFNetwork
- (void)enableNetworkDebug {
[[NSNotificationCenter defaultCenter] addObserverForName:AFNetworkingOperationDidStartNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
AFHTTPRequestOperation *op = [note object];
NSLog(@"\n\nREQUEST:%x \n%@\n\n", (NSUInteger)op.request, [TTTURLRequestFormatter cURLCommandFromURLRequest:op.request]);
}];
@simonpang
simonpang / gist:3754259
Created September 20, 2012 06:28
Use custom image in navigation bar
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavBar"] forBarMetrics:UIBarMetricsDefault];
@simonpang
simonpang / gist:3755012
Created September 20, 2012 09:58
Download photo from S3
NSString *url = [NSString stringWithFormat:@"http://XXXX.s3-ap-southeast-1.amazonaws.com/%@", path];
[cell.imageView setImageWithURL:[NSURL URLWithString:url] placeholderImage:nil];
@simonpang
simonpang / gist:3756413
Created September 20, 2012 14:57
parsing RFC3339 date
- (NSDate *)parseDate:(NSString *)object {
if ([object isKindOfClass:[NSString class]]) {
// See workaround for parsing RFC3339 dates:
// http://stackoverflow.com/questions/4330137/parsing-rfc3339-dates-with-nsdateformatter-in-ios-4-x-and-macos-x-10-6-impossib
NSError *error = nil;
NSDate *date = nil;
[[self dateFormatter] getObjectValue:&date forString:object range:nil error:&error];
return date;
}
@simonpang
simonpang / gist:3760453
Created September 21, 2012 08:54
Create RAM disk on OS X
diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://2175854`
@simonpang
simonpang / tlc.lua
Created October 15, 2012 14:06 — forked from seclorum/tlc.lua
LuaJIT ObjC bridge
-- TLC - The Tiny Lua Cocoa bridge
-- Note: Only tested on x86_64 with OS X >=10.7.3 & iPhone 4 with iOS 5
-- Copyright (c) 2012, Fjölnir Ásgeirsson
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
@simonpang
simonpang / LoginViewController.m
Last active December 15, 2015 15:39
Dreaming of promise base API for event handling
- (id)init
{
if (self = [super initNibName:nil bundle:nil]) {
[[self whenViewDidLoad] then:^{
id loginPromise = [client login:self.loginField password:self.passwordField when:[self.loginButton whenTouchDown]];
[UIAlertView presentMessage:^{ return [loginPromise alertError]; } when:[loginPromise whenFail]];
[client saveAccessToken:[self.loginPromise whenSuccess]];
[self presentModalViewController:[RegisterViewController willCreate] when:[self.registerButton whenTouchDown]];
}];
@simonpang
simonpang / gist:5292844
Created April 2, 2013 14:54
Dreaming of promise base event handling v2
- (id)init
{
if (self = [super initNibName:nil bundle:nil]) {
[[self whenViewDidLoad] then:^(id result, NSError *error) {
[[self.loginButton whenTouchDown] then:^(id result, NSError *error) {
[[client login:self.loginField.text password:self.passwordField.text] then:^(id result, NSError *error) {
[client saveAccessToken:[result token]];