2014年7月6日 星期日

iOS 開發筆記 - 計算一個字的寬度

程式碼:     NSString *words = @"Hello World! 您好!";
    for( int i=0 ; i<[words length] ; ++i ) {
        unichar word = [words characterAtIndex:i];
        CGSize wordSize = [[NSString stringWithFormat:@"%C", word] sizeWithAttributes:nil];
        NSLog(@"Char: %C, Font Width: %f", word, wordSize.width);
    }


Char: H, Font Width: 8.666016
Char: e, Font Width: 6.673828
Char: l, Font Width: 2.666016
Char: l, Font Width: 2.666016
Char: o, Font Width: 6.673828
Char:  , Font Width: 3.333984
Char: W, Font Width: 11.326172
Char: o, Font Width: 6.673828
Char: r, Font Width: 3.996094
Char: l, Font Width: 2.666016
Char: d, Font Width: 6.673828
Char: !, Font Width: 3.333984
Char:  , Font Width: 3.333984
Char: 您, Font Width: 12.000000
Char: 好, Font Width: 12.000000
Char: !, Font Width: 12.000000


若要指定 font ,可以透過設定 Attributes:

@{
    NSFontAttributeName: [UIFont fontWithName:@"Courier" size:16]
}


指定 Courier 字型: Char: H, Font Width: 9.601562
Char: e, Font Width: 9.601562
Char: l, Font Width: 9.601562
Char: l, Font Width: 9.601562
Char: o, Font Width: 9.601562
Char: , Font Width: 9.601562
Char: W, Font Width: 9.601562
Char: o, Font Width: 9.601562
Char: r, Font Width: 9.601562
Char: l, Font Width: 9.601562
Char: d, Font Width: 9.601562
Char: !, Font Width: 9.601562
Char: , Font Width: 9.601562
Char: 您, Font Width: 16.000000
Char: 好, Font Width: 16.000000
Char: !, Font Width: 16.000000

2014年7月5日 星期六

[OSX] 移除 Avira Antivir 方式 @ Mac 10.9.3



在 Mac 用小紅傘一陣子了,但小紅傘一旦有新的軟體時,常常定時顯示出來,好不厭煩 XD 為了更新軟體,以前只要透過拖拉方式把小紅傘拖進垃圾桶即可移除,再裝新版即可,最近卻發現拖進垃圾桶沒反應,找了一下正確的反安裝流程:
  • 從 Finder -> Go -> Utilities -> Avira-Uninstall
  • 從 Spotlight -> 搜尋 Avira -> Avira-Uninstall
移除之後,就可以安裝新的 Avira Antivir 啦

2014年7月3日 星期四

iOS 開發筆記 - 使用 C++ Source Code

最近把玩練習時,想說用一下 CPP 的,寫完後發現要整進 Xcode 卻發現 compile error,例如在 AppDelete.m 中:

#include "Test.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
 
    Test *obj = new Test();
 
    return YES;
}


其中 Test.h:

#ifndef __Test__Test__
#define __Test__Test__

#include <iostream>

class Test {
public:
    int x;
};


#endif /* defined(__Test__Test__) */


編譯時就會顯示找不到 iostream 等訊息,解法?早期大概有指定 Compile 參數,現在還滿容易的,只要把用到 CPP 的 Objective-C 檔案,從 .m 改成 .mm 即可。

以此就是將 AppDelete.m 更名為 AppDelete.mm ,就可以編譯成功,真是太方便了!

[Linux] 使用 wget 測試 Remote Resource Availability @ Ubuntu 14.04

wget 有 --spider 模式,挺方便的 :P

$ wget --spider http://www.google.com/favicon.ico
Spider mode enabled. Check if remote file exists.
Resolving www.google.com (www.google.com)... 173.194.33.148, 173.194.33.144, 173.194.33.145, ...
Connecting to www.google.com (www.google.com)|173.194.33.148|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [image/x-icon]
Remote file exists.

2014年7月2日 星期三

[Linux] 使用 ClamAV 掃毒 @ Ubuntu 14.04 Server

有一台Linode機器一直用來當跳板,若沒出事就不會進去逛,最近突然想到,不會不哪天被入侵還不知道?就先試看看最粗淺的用法,掃毒:

$ sudo apt-get install clamav
$ sudo freshclam
$ sudo clamscan -r /
...

----------- SCAN SUMMARY -----------
Known viruses: 3492457
Engine version: 0.98.1
Scanned directories: 13386
Scanned files: 50860
Infected files: 0
Total errors: 8826
Data scanned: 1996.67 MB
Data read: 19701.90 MB (ratio 0.10:1)
Time: 210.216 sec (3 m 30 s)

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda        47G   20G   25G  44% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
devtmpfs        996M  4.0K  996M   1% /dev
none            200M  208K  200M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            997M     0  997M   0% /run/shm
none            100M     0  100M   0% /run/user


看起來耗時不多,有沒有用就是另一回事了 XDD 例如躲在記憶體內以及沒被偵測出來的...