☆ 最近發現 GitHub 實在太強大了,真的是一個能取代 Blog 的服務,未來大概只會更新到 GitHub 上。
https://github.com/kelp404

2012-11-26

Post a photo to Facebook with Facebook JavaScript SDK

First, you should include Facebook JavaScript SDK into your web.
<script type="text/javascript" src="http://connect.facebook.net/en/all.js"></script>

Call FB.init() when $(document).ready().
$(document).ready(function () {
    // set up
    FB.init({ appId: 'Your Facebook App ID' });
});

2012-10-28

Grand Central Dispatch - Write Less Code, Get More Done

Before I knew GCD(Grand Central Dispatch), I wrote a Thread Pool to do multithread. But NSThread is very slow and need to write other messages. GCD use a block technology so that multithreaded code could be in a same message.

Why use GCD:
  • High performance.
  • Clean code.

Multithread

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    // your code. it will be run on a new thread.
    for (NSInteger index = 0; index < 1000; index++) {
        // loop
    }
});
dispatch_get_global_queue() this queue is async. Threads will be run at the same time. You could set the priority 「DISPATCH_QUEUE_PRIORITY_HIGH, DISPATCH_QUEUE_PRIORITY_DEFAULT, DISPATCH_QUEUE_PRIORITY_LOW, DISPATCH_QUEUE_PRIORITY_BACKGROUND」 to the thread.


2012-09-25

Reflection in Python

I started learning Python a few week ago. I think Python is more smart than C#. Python is a good language, because the syntax is beautiful. I like this language.

I usually use Reflection in my code, event in Python. There some code I found.

Get Dictionary From Strong-typing Object

# syntax:
object.__dict__
class ClassA(object):
    email = ''
    name = ''

cls = ClassA()
cls.email = 'kelp[at]phate.org'
cls.name = 'Kelp'

cls.__dict__
# result:
{'email': 'kelp[at]phate.org', 'name': 'Kelp'}


2012-09-10

初到中國心得 - 僕の戦場はここじゃない

以前聽了很多中國的傳說,例如中國進步很快、取代美國經濟地位、中國很厲害...等。
這次出差到中國後才親眼看見傳說中的中國,中國印象是豪放髒亂




沒有交通號誌的斑馬線上汽車看到有行人要過時是不會停的,雖然這點在台灣也一樣。

紅燈不一定要停,大部分的行人走斑馬線是不看號誌的,紅燈一樣會走、車來了也會走,行人沒有在怕汽車的,感覺像是汽車如果快撞到人的話行人會用中國功夫把車彈開一樣。

2012-09-07

OS X Terminal Note (1)

  1. Terminal Hot Key
  2. Show OS X Version
  3. Show System Information
  4. Show System Running Time
  5. Rename, Copy, Delete File
  6. Search File

2012-08-23

let UINavigationController does no pop to root in UITabBarController

Users can click the tab bar item let the NavigationController pop to the root view when the NavigationController in the TabBarController.
We can handle it by - (BOOL)tabBarController:(UITabBarController *)tabBarController.

AppDelegate.h
@interface TestAppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>

@property (strong, nonatomic) UIWindow *window;
// ............

@end

2012-08-21

set up background on UIView and UITableView

Set background of UIView:
UIImage *img = [UIImage imageNamed:@"retina_wood"];
self.view.backgroundColor = [UIColor colorWithPatternImage:img];

2012-08-18

UIActionSheet showFromRect with UITableViewCell

The UI of an UIActionSheet in an iPad is like this. It is different between an iPad and an iPhone.