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 / template_git.rb
Created July 27, 2011 08:01 — forked from activestylus/template_git.rb
Rails 3 Template: Git Setup
#----------------------------------------------------------------------------
# Git Setup
#----------------------------------------------------------------------------
file '.gitignore', <<-FILE
.DS_Store
log/*.log
tmp/**/*
config/database.yml
db/*.sqlite3
public/uploads/*
@marshluca
marshluca / gist:1105729
Created July 26, 2011 01:36
Ruby Style Guide
Original Source: https://github.com/chneukirchen/styleguide
= Christian Neukirchen's Ruby Style Guide
You may not like all rules presented here, but they work very well for
me and have helped producing high quality code. Everyone is free to
code however they want, write and follow their own style guides, but
when you contribute to my code, please follow these rules:
@marshluca
marshluca / MButton.h
Created July 21, 2011 09:54
自定义UIButton: 左1/4图标,右3/4文字
#import <Foundation/Foundation.h>
@interface MButton : UIButton {
}
@end
@marshluca
marshluca / UIScrollViewDelegate.m
Created July 15, 2011 06:02
UIScrollViewDelegate
@protocol UIScrollViewDelegate
@optional
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
@end
@interface UIScrollView : UIView
@property (assign) id <UIScrollViewDelegate> delegate;
@marshluca
marshluca / NSInvocationOperation.m
Created July 15, 2011 06:01
NSOperationQueue,NSInvocationOperation
- (void) clickButton
{
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(loadDataWithOperation)
object:nil];
[queue addOperation:operation]; // will start the operation
[operation release];
@marshluca
marshluca / detachNewThreadSelector.m
Created July 15, 2011 05:57
[NSThread detachNewThreadSelector]
- (IBAction)clickButton
{
[NSThread detachNewThreadSelector:@selector(startBackgroundJob)
toTarget:self
withObject:nil];
}
- (void)startBackgroundJob
{
[self performSelectorOnMainThread:@selector(makeProgressBarMoving)
@marshluca
marshluca / iOS_snnipets.m
Created July 14, 2011 01:10
iOS代码片段
1.倒序输出一个数组
NSMutableArray *array = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",nil];
NSArray* reversedArray = [[array reverseObjectEnumerator] allObjects];
@marshluca
marshluca / DrawGraphics.txt
Created July 3, 2011 01:18
iOS代码集锦
1.Quartz 2D Programming Guide
http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction/Introduction.html
2.Mail Composer in App
http://developer.apple.com/library/ios/#samplecode/MailComposer/index.html
3.NSNotification Center
https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Notifications/Introduction/introNotifications.html
@marshluca
marshluca / UITableView+Swipe
Created June 29, 2011 07:16
滑动UITableViewCell编辑
ios中UITaleView实现删除移动样式,当手指在每一行上滑动时,会出现删除按钮,并且点击可以实现相应的逻辑。
实现的代码:
#pragma mark – View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
[mtableView setEditing:NO animated:YES];
@marshluca
marshluca / UILabel+Size.m
Created June 29, 2011 07:14
计算UILable的宽度
myLable=[[UILabel alloc] initWithFrame:CGRectMake(0, 23, 175, 33)];
[myLable setFont:[UIFont fontWithName:@"Helvetica" size:10.0]];
[myLable setNumberOfLines:0];
[myLable setBackgroundColor:[UIColor clearColor]];
[myAdView addSubview:myLable];
UIFont *font = [UIFont fontWithName:@"Helvetica" size:10.0];
CGSize size = [text sizeWithFont:font constrainedToSize:CGSizeMake(175.0f, 2000.0f) lineBreakMode:UILineBreakModeWordWrap];
CGRect rect=myLable.frame;
rect.size=size;