Skip to content

Instantly share code, notes, and snippets.

View marshluca's full-sized avatar
🏠
Working from home

Lucas Zhang marshluca

🏠
Working from home
View GitHub Profile
@marshluca
marshluca / TurnPageViewController.m
Created November 24, 2010 09:09
TurnPageViewController
#import "TurnPageViewController.h"
@implementation TurnPageViewController
@synthesize viewArray;
@synthesize startPoint;
@synthesize currentpageNumber;
- (void)viewDidLoad {
@marshluca
marshluca / read_and_write_in_objc.m
Created November 25, 2010 06:35
read and write from documents directory
- (NSString *)documentPathForFile:(NSString *)fileName
{
NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *documentPath = [pathArray objectAtIndex:0];
NSString *filePath = [documentPath stringByAppendingPathComponent:fileName];
return filePath;
// return [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:fileName];
}
- (NSMutableArray *)loadLocalBooksFromDocument:(NSString *)fileName
@marshluca
marshluca / getContact.m
Created November 29, 2010 08:32
获取iPhone联系人
- (void)getContactList
{
ABAddressBookRef addressBook = ABAddressBookCreate();
NSMutableArray *peopleArray = (NSMutableArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
for (id *people in peopleArray)
{
// phone
ABMultiValueRef phones = (ABMultiValueRef) ABRecordCopyValue(people, kABPersonPhoneProperty);
int nCount = ABMultiValueGetCount(phones);
@marshluca
marshluca / MultilineCellInTableView.m
Created December 1, 2010 03:46
动态计算文字高度
//
// MultilineCellInTableViewViewController.m
// MultilineCellInTableView
//
// Created by Слава on 02.11.09.
// Copyright Slava Bushtruk 2009. All rights reserved.
//
#import "MultilineCellInTableViewViewController.h"
@marshluca
marshluca / uninstall_xcode
Created December 2, 2010 04:19
remove Xcode Tool logs
localhost:iOS40 terry-wang$ sudo Library/uninstall-devtools --mode=all
Password:
Use of uninitialized value $dir_name in substitution (s///) at Library/uninstall-devtools line 153.
Start time: 2010年12月 2日 星期四 12时14分39秒 CST
Started uninstalling versioned non-relocatable developer tools content.
Shutting down distcc...
Analyzing devtools package: 'com.apple.pkg.VersionedDeveloperToolsSystemSupportLeo'...
Analyzing package: 'Adobe Flash Player.pkg'...
Analyzing package: 'AirPortUtility.pkg'...
Analyzing package: 'AppleIntermediateCodec.pkg'...
@marshluca
marshluca / CoreHelloWorld.m
Created December 8, 2010 02:02
01a - CoreHelloWorld
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"SampleAppDelegate");
[pool release];
return retVal;
CGRect rect = [[UIScreen mainScreen] bounds];
NSLog(@"window: %f,%f,%f,%f",rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
window: 0.000000,0.000000,320.000000,480.000000
@marshluca
marshluca / willRotateToInterfaceOrientation.m
Created December 8, 2010 04:00
willRotateToInterfaceOrientation:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {
CGRect apprect;
apprect.origin = CGPointMake(0.0f, 0.0f);
if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight))
apprect.size = CGSizeMake(480.0f, 300.0f);
else
apprect.size = CGSizeMake(320.0f, 460.0f);
@marshluca
marshluca / DragView.m
Created December 8, 2010 04:12
移动到新的位置
#import <UIKit/UIKit.h>
@interface DragView : UIImageView
{
CGPoint startLocation;
}
@end
@implementation DragView
@marshluca
marshluca / appDelegate.m
Created December 9, 2010 02:05
Splash in iOS
1. 将你需要的splash界面的图片,存成Default.png
2. 在XXXAppDelegate.m程序中,插入如下代码:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//–insert a delay of 5 seconds before the splash screen disappears–
[NSThread sleepForTimeInterval:5.0];
// Override point for customization after application launch.
// Add the view controller’s view to the window and display.
[window addSubview:viewController.view];
@marshluca
marshluca / oauth_process.rb
Created December 10, 2010 08:52
新浪微薄的OAuth 1.0认证
# OAuth认证包括以下四步内容
# 1. 获取Request Token
# 2. 用户确认授权
# 3. 换取Access Token
# 4. 访问受限资源
require 'rubygems'
gem 'oauth','0.4.3'
require 'oauth'