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 / UIImageWriteToSavedPhotosAlbum.m
Created December 20, 2010 05:47
save image to local album
- (void)saveImageToAlbum
{
UIImage *image = currentPage.imageView.image;
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
if (error == nil)
@marshluca
marshluca / FMDB.m
Created December 29, 2010 01:41
Handle SQLite in Objc
#import <Foundation/Foundation.h>
#import "FMDatabase.h"
#import "FMDatabaseAdditions.h"
#define FMDBQuickCheck(SomeBool) { if (!(SomeBool)) { NSLog(@"Failure on line %d", __LINE__); return 123; } }
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// delete the old db.
select * from sqlite_master where type='index';
drop index vegetables_name;
create index vegetables_name on vegetables(name);
insert into vegetables values ("luobo", "green", "nice luobo");
create table vegetables (name char not null, color char not null default 'green', description char);
@marshluca
marshluca / activity_indicator_as_subview.m
Created January 6, 2011 05:18
UIActivityIndicator as Accessory View
#define SPINNER_SIZE 25
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
// Get center of cell (vertically)
int center = [cell frame].size.height / 2;
@marshluca
marshluca / round_corner_on_webview
Created January 6, 2011 05:23
Rounded Corners on UIWebview
// This is required in order to access the CALayer properties
#import <QuartzCore/QuartzCore.h>
// Create UIWebview
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(5, 20, 310, 220)];
// Round corners using CALayer property
[[webView layer] setCornerRadius:10];
[webView setClipsToBounds:YES];
@marshluca
marshluca / Ads.m
Created January 11, 2011 05:34
Ads.h
//
// ItemWebViewController.m
// Woyi
//
// Created by wang xuefeng on 10-9-27.
// Copyright 2010 5Yi.com. All rights reserved.
//
#import "MUtility.h"
#import "WoyiAppDelegate.h"
@marshluca
marshluca / NSInvocationOperation.m
Created January 26, 2011 08:19
使用NSInvocationOperation 处理多线程
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Load"
style:UIBarButtonItemStyleDone
target:self
action:@selector(loadData)];
NSMutableArray *_array = [[NSMutableArray alloc] initWithCapacity:10000];
self.array = _array;
@marshluca
marshluca / unicorn.rb
Created February 3, 2011 07:03
unicorn+nginx配置
# Sample verbose configuration file for Unicorn (not Rack)
#
# This configuration file documents many features of Unicorn
# that may not be needed for some applications. See
# http://unicorn.bogomips.org/examples/unicorn.conf.minimal.rb
# for a much simpler configuration file.
#
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
# documentation.
@marshluca
marshluca / mutiThread.m
Created February 10, 2011 07:47
友盟多线程推送机制
//
// UMeng.m
// Gallery
//
// Created by marshluca on 11-2-10.
// Copyright 2011 www.5yi.com. All rights reserved.
//
#import "UMeng.h"
#import "MBase.h"
@marshluca
marshluca / wordress_permalink
Created February 12, 2011 02:00
/etc/apache2/sites-enabled/000-default