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 / douban_oauth.rb
Created December 10, 2010 10:21
豆瓣OAuth认证
# Douban OAuth认证包括以下四步内容
# 1. 获取Request Token
# 2. 用户确认授权
# 3. 换取Access Token
# 4. 访问受限资源
require "rubygems"
gem 'oauth','0.4.3'
require 'oauth'
@marshluca
marshluca / FadeAnimation.m
Created December 11, 2010 10:00
视图切换效果, slide, fade, flip
- (void) fadeOut: (id) sender
{
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[[self.view viewWithTag:999] setAlpha:0.0f];
[UIView commitAnimations];
self.navigationItem.rightBarButtonItem = BARBUTTON(@"Fade In", @selector(fadeIn:));
}
@marshluca
marshluca / getPageWhenScrollView.m
Created December 14, 2010 06:03
滚动scrollView的时候,获取当前page
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
CGFloat pageWidth = galleryScrollView.frame.size.width;
int currentPage = floor((galleryScrollView.contentOffset.x - pageWidth / 2) / 320) + 1;
[self loadSelectedPage:currentPage];
}
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
/*@protocol MActivityIndicatorProtocol
- (void)handleTask:(SEL)task;
- (void)hideIndicator;
@end*/
@marshluca
marshluca / NSHTTPCookie.m
Created December 16, 2010 06:33
Handle NSHTTPCookieStorage
for (NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
@marshluca
marshluca / ApplicationWillExit.m
Created December 17, 2010 01:31
按住Home后,退出保存数据
- (void)applicationWillResignActive:(UIApplication *)application {
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
NSLog(@"applicationWillResignActive");
UIApplication *app = [UIApplication sharedApplication];
@marshluca
marshluca / NSUserDefaults.m
Created December 17, 2010 02:00
persistence
NSDictionary *magazineDict = [NSDictionary dictionary];
[[NSUserDefaults standardUserDefaults] registerDefaults:magazineDict];
// write data to /Library/Preferences.
[[NSUserDefaults standardUserDefaults] synchronize];
@marshluca
marshluca / MUtiliity.m
Created December 17, 2010 04:32
MUtility
//
// MUtility.m
// Magazine
//
// Created by wang xuefeng on 10-12-9.
// Copyright 2010 www.5yi.com. All rights reserved.
//
#import "MUtility.h"
#import "MFoundation.h"
@marshluca
marshluca / MPageView.h
Created December 17, 2010 07:11
PageView
//
// MPageView.h
// Magazine
//
// Created by wang xuefeng on 10-12-9.
// Copyright 2010 www.5yi.com. All rights reserved.
//
#import <UIKit/UIKit.h>
@marshluca
marshluca / MScrollView.h
Created December 17, 2010 07:30
Mscrollview
//
// MScrollView.h
// Magazine
//
// Created by wang xuefeng on 10-12-16.
// Copyright 2010 www.5yi.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "MPageView.h"