water's blog

NSExpression example

NSExpression is a very powerful class in iOS/OSX that calculate formula. We can also pass arguments or parameters to the formula:

NSExpression *expression1 = [NSExpression expressionWithFormat: @"1+2"];
NSLog(@"expression1 %@", [expression1 expressionValueWithObject:nil context:nil]);
NSExpression *expression2 = [NSExpression expressionWithFormat: @"1+%@-%@" argumentArray:@[@1.2, @2.2]];
NSLog(@"expression2 %@", [expression2 expressionValueWithObject:nil context:nil]);
NSMutableDictionary *context = [NSMutableDictionary dictionaryWithDictionary:

Google Maps for iOS 2.0 offline map

Google Maps 繼 Android 版更新後終於也推出 iOS 版,最重要當然是支援iPad了。

當 Android 新版更新時,用家最大問題是投訴沒有了離線功能。於是 Google 便用彩蛋把這功能加回來:

http://chinese.vr-zone.com/73123/google-added-back-google-maps-offline-l...

最有趣是,原來這個功能在 iOS 版也是適用的:

首先只要把地圖 zoom 到你想離線使用的地方,但注意不可以太大的。

然後在 search Bar 的地方打入 "ok maps"
IMG_3902.jpg

之後程式便會把資料儲存在 device 裏面,然後你便可以離線應用這個地區的地圖了。

IMG_3901.jpg

Eclipse and Macbook Pro Retina

By default, eclipse doesn't support Retina display of new Macbook Pro that all text in Eclipse is pixelated. Actually Eclipse support Retina display but you have to enable it manually.

1. Do "Show package contents" on the Eclipse.app.
2. Edit Contents/Info.plist using your favorite text editor. Just above

</dict>
</plist>

Place this:

<key>NSHighResolutionCapable</key>
<true/>

Free XCode plugins for XCode 4

Some opensource free plugins that you can add to your XCode to increase your productivity. All tested on the new XCode 4.6.

Mini Xcode Plugin
You know there is a fat toolbar at the top of the your windows since XCode 4. Although you can hide this tool bar, it will also hide the current project scheme and target. After installed this plugins, it will:
- add a popup menu at the top left or the windows that shows project scheme and target when tool bar is hidden.
- add shortcut (Ctrl+7, Ctrl+8) to select the schemes and targets.

Convert async block to sync

Since iOS 5, many apis will only provide block version and so we will get the result in async order. Sometimes we may want to get the result immediately by scarifying the benefit of GCD.

In old style, we can't do it using NSCondition:

__block NSCondition *condition = [[NSCondition alloc] init];
__block ALAssetsGroup *ret = nil;
ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) {
[condition lock];
ret = group;
[condition signal];
[condition unlock];
};

Set priority in custom queue of GCD

In iOS GCD, you can use GCD queue to serialize operation by using DISPATCH_QUEUE_SERIAL parameters:

queue = dispatch_queue_create("hk.com.waterworld.previewRenderQueue", DISPATCH_QUEUE_SERIAL);

then you can create a queue dispatch like:

dispatch_async(self.renderQueue, ^{
... your code here ...
});

but the priority of the queue is unknown, so sometimes, when you queue a lot of task to this queue. It still block the foreground task and make the user interface not smooth.

If fix it, we can:

dispatch_async(self.renderQueue, ^{

香港 Passbook coupon (不定期更新)

Subway - 免費汽水
http://pass.is/subway

Seven Eleven - 購物折扣
http://711campaign.hk

expansys 購買經驗

呢間 online shop 口碑一直都唔係幾好,不過今次我見佢賣 microusb -> lightning adaptor 價同英國價差不多 (當時此 adaptor 香港未有得賣),又見比佢扼咪最多幾百蚊於是試下:
Screen Shot 2012-11-03 at 11.09.13 PM.png
個 email 仲大大得字寫明 "a contract will then be formed between us" 驚我取消 order。

等呀等十幾日過後,收到這封 email,話要加價,我當然 email 話唔得,佢一定要fulfill order,我都預備了d email 準備 send 去消委會。
Screen Shot 2012-11-03 at 11.10.12 PM.png
點知第二日佢好有誠意打電話比我,叫我補錢。我話唔得,你個 confirm email 咪話乜野 contract between us,一定要原價送貨。佢竟然又話 ok…

奇怪既事係第二日,Apple 香港 online shop 突然又有得賣,價錢也是 $158

http://store.apple.com/hk/product/MD820ZM/A/lightning-to-micro-usb-adapt...

咁我真係唔知佢 d 貨其實係咪 Apple HK 既…

Windows 8 Pro Upgrade 賣大包

Windows 8 終於開售,唔買都來睇下呀。Windows 8 除了可以買 retail 版外,也可以網上買 online upgrade version:

http://www.windowsupgradeoffer.com/zh-HK/Home/ProgramInfo

Upgrade version (升級版)原價 $325,新買 Windows 7 的用家可以以特價 $119 購買升級版,原則上,升級版只可以安裝在一部原本有 Windows 7 的 PC,網友測試,你的 Windows 7 無論是正版或翻版也可以 upgrade 的,似乎 microsoft 想大家從良吧。

最有趣是,這個 $119 upgrade offer 基本上也是原完全不會驗證你有沒有和何時買過 Windows 7 的,也不需要你填 Windows 7 的 key,於是當你到此處註冊時:

https://www.windowsupgradeoffer.com/zh-HK

Screen Shot 2012-10-28 at 6.23.58 PM.png Screen Shot 2012-10-28 at 6.23.36 PM.png

iPhone 5 抽獎自動化

身在香港,現時如果想買部 iPhone 5 玩下,一是上台出機,一是到以下網站抽獎:

https://reserve.apple.com/HK/en_HK/reserve/iPhone

但是日日抽太辛苦,於是自己寫了 script 作 automation,方法一是用 web browser 的 automation extension,但身為programmer 我比較喜歡可以一個command line 就做完所有事。於是我用第二個方法,用 headless browser,所謂 headless browser 即是是沒有 ui 我 browser,一般比較流行的是 Mechanize

http://mechanize.rubyforge.org/

但考慮到自己 ruby 戰鬥力比較差,於是用了 phantomjs

http://phantomjs.org

phantomjs 比 mehanize 更好的是,它是內置 webkit,所以他是可以隨時 render screen capture,用來 debug 非常方便。

Syndicate content