Skip to content

Instantly share code, notes, and snippets.

View zonble's full-sized avatar

Weizhong Yang a.k.a zonble zonble

View GitHub Profile
@zonble
zonble / main.m
Created May 10, 2009 20:55
Dump a list of methods of an Obj-C Class
We couldn’t find that file to show.
@class LFReachability;
typedef enum {
LFReachabilityNetworkNone = 0,
LFReachabilityNetworkWifi = 1,
LFReachabilityNetworkWWAN = 2
} LFReachabilityNetworkType;
@protocol LFReachabilityDelegate <NSObject>
# 快快樂樂用 PyObjC 建立 DO
import objc
from Cocoa import *
self.service = NSConnection.rootProxyForConnectionWithRegisteredName_host_("SERVICE_NAME", None)
protocol = objc.protocolNamed("PROTOCOL")
elf.service.setProtocolForProxy_(protocol)
@zonble
zonble / gist:204496
Created October 7, 2009 22:15
取得所有 Mac OS X 中可用之繁體中文字體列表
NSArray *a = [[NSFontManager sharedFontManager] availableFonts];
NSMutableArray *tradChineseFontNames = [NSMutableArray array];
NSStringEncoding tradChinese = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingMacChineseTrad);
for (NSString *name in a) {
NSFont *font = [NSFont fontWithName:name size:12.0];
NSStringEncoding e = [font mostCompatibleStringEncoding];
if (e == tradChinese) {
// CFStringRef s = CFStringGetNameOfEncoding(CFStringConvertNSStringEncodingToEncoding(e));
// NSLog(@"name:%@ display name:%@ encoding: %@", name, [font displayName], (NSString *)s);
[tradChineseFontNames addObject:name];
- (NSMethodSignature*)methodSignatureForSelector:(SEL)aSelector
{
const char *selname = sel_getName(aSelector);
NSLog(@"trying to call %s", selname);
return [super methodSignatureForSelector:aSelector];
}
- (BOOL)respondsToSelector:(SEL)aSelector
{
NSLog(@"trying to determine %s", sel_getName(aSelector));
@zonble
zonble / Yal Menfi
Created October 29, 2009 15:12
Yal Menfi 歌詞中文翻譯
aw goulou lommi matebkish, yal menfi
告訴我母親別哭,喔!逃亡
waldek rabbi maykhalihsh, yal menfi
真主不會拋棄妳的孩子,喔!逃亡
aw goulou lommi matebkish, yal menfi
告訴我母親別哭,喔!逃亡
waldek rabbi maykhalihsh, yal menfi
真主不會拋棄妳的孩子,喔!逃亡
aw ya dakhal fi set biban, yal menfi
قولو لأمي ما تبكيش... يا منفى
aw goulou lommi matebkish, yal menfi
告訴我母親別哭,喔!逃亡
ولدك ربي ما يخليش... يا منفى
waldek rabbi maykhalihsh, yal menfi
真主不會拋棄妳的孩子,喔!逃亡
قولو لأمي ما تبكيش... يا منفى
aw goulou lommi matebkish, yal menfi
告訴我母親別哭,喔!逃亡
ولدك ربي ما يخليش... يا منفى
@zonble
zonble / iPhone 上產生一個新的 Image context
Created February 2, 2010 10:11
在 iPhone 上產生一個新的 image context 並且產生 UIImage
// 每次都忘記要這樣開頭…
UIGraphicsBeginImageContext(CGSizeMake(320.0, 320.0));
CGContextRef context = UIGraphicsGetCurrentContext();
defaultCoverImage = [UIGraphicsGetImageFromCurrentImageContext() retain];
UIGraphicsEndImageContext();
// PTYTextView 27858
if([self hasMarkedText]) {
int len=[markedText length];
if (len>WIDTH-x1) len=WIDTH-x1;
NSRect inputFrame = NSMakeRect(floor(x1 * charWidth + MARGIN), (yStart + [dataSource numberOfLines] - HEIGHT) * lineHeight + (lineHeight - cursorHeight), ceil((WIDTH-x1)*cursorWidth),cursorHeight);
[markedText drawInRect:inputFrame];
NSAttributedString *attributedStringBeforeCursor = [markedText attributedSubstringFromRange:NSMakeRange(0, IM_INPUT_SELRANGE.location) ];
NSRect spaceFrame = [attributedStringBeforeCursor boundingRectWithSize:inputFrame.size options:0];
NSRect cursorFrame = NSMakeRect(inputFrame.origin.x + spaceFrame.size.width, inputFrame.origin.y, 2.0, inputFrame.size.height);
@zonble
zonble / Big5toUTF8.m
Created November 2, 2010 14:08
Big5 字串轉成 UTF8 字串
NSStringEncoding big5 = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingBig5_HKSCS_1999);
NSString *string = [[NSString alloc] initWithData:data encoding:big5];
NSData *UTF8Data = [string dataUsingEncoding:NSUTF8StringEncoding];
[string release];