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
class Polygon
@@sides = 10
def self.sides
@@sides
end
end
puts Polygon.sides # => 10
class Triangle < Polygon
# put this in your lib folder as logger_format.rb and
# require it in your environment or an initializer
class Logger
def format_message(level, time, progname, msg)
"#{time.to_s(:long)} -- #{msg}\n"
end
end
@jakebellacera
jakebellacera / nginx-apache-reverse-proxy-wordpress-mu-vhost.conf
Created September 21, 2010 23:39
Useful nginx virtual host configuration for reverse proxy (proxy_pass) with Apache
# useful nginx configuration for reverse proxy with Apache
# edit lines 8, 11, and 30
# taken from: http://syslog.tv/2010/01/11/debian-apache-2-nginx-wordpress-mu/
# edits by jakebellacera (http://github.com/jakebellacera && http://jakebellacera.com)
server {
listen 80;
server_name domain.com *.domain.com; # edit this to your domain
@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 / 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'
@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:));
}