Skip to content

Instantly share code, notes, and snippets.

View huobazi's full-sized avatar
🎯
Focusing

Marble Wu huobazi

🎯
Focusing
View GitHub Profile
@huobazi
huobazi / sync.rb
Created September 23, 2011 04:55 — forked from dongyuwei/sync.rb
auto sync local workcopy to remote server
#author [email protected]
require 'rubygems'
require 'fsevents'
require 'net/ssh'
require 'net/scp'
require 'ruby-growl'
host = "10.210.74.63"
username = "my name"
password = "my password"
@huobazi
huobazi / scp-ruby.rb
Created September 23, 2011 04:56 — forked from dongyuwei/scp-ruby.rb
使用ruby scp库批量上传文件夹,并且显示进度
#!/usr/bin/ruby
#@auther [email protected]
require 'rubygems'
require 'net/ssh'
require 'net/scp' #gem install net-scp
host = "ip address"
username = "your name"
password = "your password"
@huobazi
huobazi / webget.rb
Created November 8, 2011 08:29 — forked from nebuta/webget.rb
Get google search result
require 'net/http'
require 'cgi'
require 'rubygems'
require 'hpricot'
require 'open-uri'
require "resolv-replace"
require 'timeout'
BASE_URL = "http://www.google.com/search?"
LANG = "ja"
alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split("")
base = alphabet.length
exports.encode = (i) ->
return alphabet[0] if i is 0
s = ""
while i > 0
s += alphabet[i % base]
i = parseInt(i / base, 10)
@huobazi
huobazi / createDocumentSubdir.m
Created November 16, 2011 05:35 — forked from slashingweapon/createDocumentSubdir.m
Useful Objective-C Snippets
// Create a path to a directory, and make sure it exists.
// The iOS documentation will tell you that URLs are preferred, but there is no createDirectory method for
// URLs. So we have to use string paths instead.
// Create a sub-directory in the application's Documents directory. Return the path on success, or nil on failure.
- (void)createDocumentSubdirectory:(NSString*)dirName {
NSString *retval = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dirPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:dirName];
NSFileManager *fm = [[NSFileManager alloc] init];
@huobazi
huobazi / Singleton.h
Created November 16, 2011 05:37
Objective-c singleton
//from http://boredzo.org/blog/archives/2009-06-17/doing-it-wrong
@interface SingletonManager : NSObject {}
+ (id)sharedManager;
@end
@huobazi
huobazi / gist:1421368
Created December 2, 2011 01:58
在iOS5内打开系统设置页面
- (IBAction)btnSystemSettingTouchUpInside:(id)sender {
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"] ];
}
- (IBAction)btnTwitterSettingTouchUpInside:(id)sender {
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"prefs:root=TWITTER"] ];
}
- (IBAction)btnBlueToothSettingTouchUpInside:(id)sender {
@huobazi
huobazi / UITextField+HideKeyBoard.h
Created December 9, 2011 06:00
iOS 点击背景自动隐藏键盘
#import <UIKit/UIKit.h>
@interface UITextField (HideKeyBoard)
-(void)hideKeyBoard:(UIView *)view;
@end
@huobazi
huobazi / rm iteratively files in a sub-directory.
Created December 27, 2011 04:50
迭代删除某个目下的文件
# 删除当前目录下所有 dep 文件
find . -name *.dep -type f -exec rm -rf {} \;
# 删除当前目录下所有 linux64GccDPOpt 目录(包括里面的文件)
find . -name "linux64GccDPOpt" -type d -exec rm -rf {} \;
删除目录的命令提示:
@huobazi
huobazi / gist:1813804
Created February 13, 2012 04:54
UIActionSheetDelegate
#pragma mark-
#pragma mark UIActionSheetDelegate with logOff
- (void) onLogOffButtonClick:(id)sender{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"确认要退出登录吗?" delegate:self cancelButtonTitle:@"不退出" destructiveButtonTitle:@"退出" otherButtonTitles:nil, nil];
[actionSheet showFromTabBar:self.navigationController.tabBarController.tabBar];
XX_RELEASE_SAFELY(actionSheet);
}
- (void)logOff{