Jack.Y’s Blog

A Programer’s Story.

Something about Nike+ sensor

Nike+ sensor and receicer

所有数据由两件设备的协同工作得到——Nike+ 传感器以及接收器。我们接下来详细分析一下它们。

就像手机和电视一样,Nike + iPod传感器和接收器利用无线电波交流。传感器监测跑者的每一个脚步,然后将此信息播送到接收器上。接收器将信息导入ipod nano,后者通过屏幕或耳机将信息传递给跑者。

压电材料能够在形变时产生电脉冲

压电材料

传感器置于Nike+跑鞋鞋垫下的一个孔洞中。它会通过其压电加速计检测到跑者的脚步。压电材料能在形变时产生电流,或者在导通电流时产生形变。压电式换能器,通常用于扬声器中,在接触到电流时迅速改变形状。而压电传感器,采用石英,硅,或人造晶体,在受挤压,移动或弯折时产生电流。

压电传感器可以非常小——圆圈中的传感器为PlayStation 3的控制器提供动作感应能力。

PlayStation 3的传感器

这些发电机一样的晶体尺度通常是微观的。根据晶体的切割方式,它们通常在朝着一个特定方向或沿着一个特定平面被挤压时产生电荷。因此,压电传感器可以非常小,同时非常精确。除了用于Nike+传感器外,小巧的压电传感器还能为PlayStation 3和任天堂Wii的控制器提供动作感应能力。

Nike+传感器的加速计置于其电池顶端。一个发射器将信号播放到相配的接收器上。

Nike+ sensor正面

Nike+传感器中的加速计可以检测到何时一个人的脚踏于地上。当一个人静止直立或是漫步时,他的触地的时间比在空中的时间要长。然而在慢跑或者冲刺时,他的脚触地的时间就越来越少了。他跑得越快,他的脚接触地面的时间也随之减少。基于这个行走和跑步的基本特点,一个处理器可以用方程将触地时间转换成跑步速度。如果跑者利用跑一段已知距离,设置一个基本读数来校正传感器,这个过程会更精确。

加速计也担当着传感器开关的角色。鞋子不再移动后,加速计检测不到脚步——其停止传输数据。在失去加速计的输出后,传感器最终将自己设为睡眠状态。但是一旦一个跑者穿上鞋子并走上两步,传感器输出电脉冲并继续运行。传感器也有一个物理开关,可是直接将元件关闭;元件会持续关闭状态直到某个人再次按下开关。此举可以在某人不跑步或用其他鞋跑步时节省电池寿命(内置1000小时的电池无法更换)。

开关,处理器和天线被放置于传感器背面

Nike+ sensor背面

接收器的处理器位于印刷电路板的底面。多针脚连接头将接收器连接在nano的dock连接处

Nike+ 接收器正面

当一个人第一次使用Nike + iPod系统时,传感器和接收器间要建立连接。接收器要学习认出配套的特定传感器的识别代码。因此,很多人可以在一起跑步,而它们的Nike + iPod传感器不会干扰到对方。如果一个家庭中的数个成员使用同一个ipod,配不同的传感器,接收器会学习识别每一个传各期,而nano可以为不同用户存储不同的设置。

Nike+接收器的天线和接收元件可以检测到从发射器发射的信号

Nike+ 接收器背面

此系统是灵活的,60英尺(18.2米)的发射器范围使此系统的两个部分相互失去联系情况几乎不可能发生。然而,传感器的相对长程的传输距离使人们担心Nike+系统的隐私保护问题。

2006年11月,华盛顿大学的计算机科学与工程系的人发表了一篇论文详细阐述了Nike + iPod Sport Kit怎样能够被用于违法目的。此论文指出,发射器无论接收器是否在附近,是否插入ipod,都会传输数据。论文的作者表示,这种持续的传输可能被利用于侵犯他人隐私。

source: http://electronics.howstuffworks.com/nike-ipod.htm


Install PhpBeautifier plugin for Sublime text 2 in Mac

1. Install PhpBeautifier from pear channel : sudo pear install –alldeps channel://pear.php.net/php_beautifier-0.1.15

2. Install PhpBeautifier plugin in Sublime text. Press cmd+shift+p and select Package Control:Install Package. Then select PhpBeautifier.

sublime_package_install

3. Select Browse Packages… in menu. Find PhpBeautifier folder and edit php_beautifier.py in it.

sublime_menu_package

4. Edit line in php_beautifier.py

cmd = “php_beautifier”

to

cmd = “/Users/username/pear/bin/php_beautifier”

5. Edit Pear.filter.php , phpBB.filter.php in /Users/username/pear/share/pear/PHP/Beautifier/

comment this line

require_once(“PEAR/Config.php”);

6. Press cmd+shift+p and select Format:Php


How to create a simple Launcher app for Android

1. we need make this app as home launcher. Bind the HOME key press.

When you click the HOME key. This selector shows up.

55_2_48be3591a12df52 Add two category to AndroidManifest.xml

1
2
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />

AndroidManifest.xml:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.son1c.launcher"
      android:versionCode="1"
      android:versionName="1.0">
      
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MainActivity"
                  android:label="@string/app_name"></application>
                  
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

2. List all apps in Android

Most launders is used to list apps.

55_2_3b434ff967012d6

1) Modify main.xml and add GridView to it.
1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <GridView android:layout_width="match_parent"
        android:id="@+id/apps_list"
        android:numColumns="4"
        android:layout_height="wrap_content">
2) Search all the apps by PackageManager
1
2
3
4
5
6
private void loadApps() {
    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    mApps = getPackageManager().queryIntentActivities(mainIntent, 0);
}
3) Add adapter for GridView
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class AppsAdapter extends BaseAdapter {

        public AppsAdapter() {
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView i;
            if (convertView == null) {
                i = new ImageView(MyHome.this);
                i.setScaleType(ImageView.ScaleType.FIT_CENTER);
                i.setLayoutParams(new GridView.LayoutParams(50, 50));
            } else {
                i = (ImageView) convertView;
            }
            ResolveInfo info = mApps.get(position);
            i.setImageDrawable(info.activityInfo.loadIcon(getPackageManager()));

            return i;
        }

        public final int getCount() {
            return mApps.size();
        }

        public final Object getItem(int position) {
            return mApps.get(position);
        }

        public final long getItemId(int position) {
            return position;
        }
}
4) Add onItemClick for GridView
1
2
3
4
5
6
private OnItemClickListener listener = new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
        //TODO....
    }
};
5) Launch app when click
1
2
3
4
5
6
7
8
9
10
11
12
13
14
public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
            ResolveInfo info = mApps.get(position);
            // Package Name
            String pkg = info.activityInfo.packageName;
            // Main activity of app
            String cls = info.activityInfo.name;

            ComponentName componet = new ComponentName(pkg, cls);

            Intent i = new Intent();
            i.setComponent(componet);
            startActivity(i);
        }
}
6) Disable the BACK key
1
2
3
4
5
6
7
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_BACK) {
		return true;
	} else {
		return super.onKeyDown(keyCode, event);
	}
}
Finally the whole Activity code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package com.son1c.launcher;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class MainActivity extends Activity {

	private List<resolveinfo> mApps;
	private GridView mGrid;
	private OnItemClickListener listener = new OnItemClickListener() {
		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
			ResolveInfo info = mApps.get(position);
			String pkg = info.activityInfo.packageName;
			String cls = info.activityInfo.name;
			ComponentName componet = new ComponentName(pkg, cls);</resolveinfo>

			Intent i = new Intent();
			i.setComponent(componet);
			startActivity(i);
		}

	};

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		loadApps();
		setContentView(R.layout.main);
		mGrid = (GridView) findViewById(R.id.apps_list);
		mGrid.setAdapter(new AppsAdapter());

		mGrid.setOnItemClickListener(listener);
	}

	private void loadApps() {
		Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
		mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

		mApps = getPackageManager().queryIntentActivities(mainIntent, 0);
	}

	public class AppsAdapter extends BaseAdapter {
		public AppsAdapter() {
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			ImageView i;

			if (convertView == null) {
				i = new ImageView(MainActivity.this);
				i.setScaleType(ImageView.ScaleType.FIT_CENTER);
				i.setLayoutParams(new GridView.LayoutParams(120, 120));
				i.setPadding(12, 12, 12, 12);
			} else {
				i = (ImageView) convertView;
			}

			ResolveInfo info = mApps.get(position);
			i.setImageDrawable(info.activityInfo.loadIcon(getPackageManager()));

			return i;
		}

		public final int getCount() {
			return mApps.size();
		}

		public final Object getItem(int position) {
			return mApps.get(position);
		}

		public final long getItemId(int position) {
			return position;
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}
	}
}

Visit Android market in app with market:// link

Using Intent in your Activity to visit Android market:

1
2
3
Intent installIntent = new Intent("android.intent.action.VIEW");
installIntent.setData(Uri.parse("market://search?q=pname:"+packageName));
startActivity(installIntent);

Visit a app’s details by package name:

market://details?id=<app package name>
Example:market://details?id=com.son1c.adsense.lite

Search a app by package name:

market://search?q=pname:<app package name>
Example:market://search?q=pname:com.son1c.adsense.lite

Search apps by developer name:

market://search?q=pub:<developer name>
Example:market://search?q=pub:Jack

Search apps by keyword

market://search?q=<keyword>
Example:market://search?q=adsense

Union search
Using multi search conditions

Example:market://search?q=adsense pub:Jack


How to disable Android home menu back search keys out of apps or change keys layout

If you want to disable the home/menu/back/search keys or key layout in your apps. You can add some code response the key press event. But if you want to do this out of your apps, you can change the config of system key layout. Of course you have to root first.

You can find *.kl files in /system/usr/keylayout .

Here are some instructions for the files.

AVRCP.kl - Key layout used for Bluetooth AVRCP support.
Generic.kl - Generic key layout file for full alphabetic US English PC style external keyboards.
qwerty.kl - Emulator keyboard layout #1.
Vendor_045e_Product_028e.kl - XBox 360 USB Controller
Vendor_046d_Product_c216.kl - Logitech Dual Action Controller
Vendor_046d_Product_c294.kl - Logitech G25 Racing Wheel (in Compatibility Mode)
Vendor_046d_Product_c299.kl - Logitech G25 Racing Wheel (in Native Mode)
Vendor_046d_Product_c532.kl - Logitech Revue Wireless keyboard
Vendor_054c_Product_0268.kl - Sony Playstation(R)3 Controller
Vendor_05ac_Product_0239.kl - Apple Wireless Keyboard
Vendor_22b8_Product_093d.kl - Motorola Bluetooth Wireless Keyboard.

Edit one .kl file for example.

Here is one line of .kl file.

key 158 BACK WAKE_DROPPED

Explain:
158 - key code
BACK - key function
WAKE - wake up device with sending message to apps
WAKE_DROPPED - wake up device without sending message to apps

We can change BACK to MENU, save the file, restart. Than BACK key changed to MENU key.

So than we can disable any keys or key layout of your device.


php

Using gdb debug php core dump file

1.Using command file you can find this corefile was created by php-cgi

1
2
$ file corefile
corefile: ELF 64-bit LSB core file AMD x86-64, version 1 (SYSV), SVR4-style, from 'php-cgi'

2.Using command gdb debug. First parameter is the path of bin creator. Second parameter is core file path.

1
$ gdb ~/php/bin/php-cgi corefile
Then lots of stack information and (gdb) shows up.

3.Load source files.

1
(gdb)soucre ~/php-5.2.8/.gdbinit
3、Using command zbacktrace shows stack.
1
(gdb) zbacktrace
1
2
3
4
5
6
7
8
9
10
[0xbfff9750] ral() /home/work/php/phplib/Base.php:63
[0xbfff9900] __call()
[0xbfff9d00] INCR() /home/work/app/models/service/data/RedisCount.php:45
[0xbfff9fe0] getCont() /home/work/app/models/service/page/userinfo/submit/Total.php:22
[0xbfffa190] process()
[0xbfffa510] call_user_func_array() /home/work/app/library/web/PageService.php:33
[0xbfffa7a0] execute() /home/work/app/actions/userinfo/submit/total.php:18
[0xbfffaa00] doExecute() /home/work/app/library/uibase/Action.php:40
[0xbfffabb0] execute()
[0xbfffb0e0] run() /home/work/webroot/index.php:10

4、Using command bt

1
(gdb) bt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#0  0x000000302b807abc in pthread_mutex_lock () from /lib64/tls/libpthread.so.0
#1  0x0000002a9bf58564 in AutoLock (this=0x7fbfff7d50, lock=@0x2a9d7a1af0) at ./util/Lock.h:36
#2  0x0000002a9bf5a91a in forum::HealthyStatus::getSelectRate (this=0x2a9d7a1a98, timeout=100, checkTime=3, minRate=0.10000000000000001)
    at filter/HealthyFilter.cpp:80
#3  0x0000002a9bf5b29b in forum::HealthyFilter::doFilter (this=0x1dd88e0, request=0x7fbfff8610) at filter/HealthyFilter.cpp:239
#4  0x0000002a9bf55f9c in forum::ChainFilter::doFilter (this=0x1dd86c0, request=0x7fbfff8610) at filter/ChainFilter.cpp:19
#5  0x0000002a9bf537ba in forum::CamelSuperStrategy::fetchServer (this=0x1ddd850, req=0x7fbfff8f00) at strategy/CamelSuperStrategy.cpp:140
#6  0x0000002a9bf39753 in odp::CamelService::fetchServer (this=0x1dd7d00, req=0x7fbfff9420) at CamelService.cpp:480
#7  0x0000002a9bf47e2b in odp::WorkerManager::fetchServer (this=0x13c6210, serviceName=0x2aa017c088 "Redis_pic_counter", req=0x7fbfff9420) at WorkerManager.cpp:282
#8  0x0000002a9bee02a0 in camel_call (service=0x2aa017c088 "Redis_pic_counter", method=0x2aa01735a8 "INCR", request_value=0x2aa01735e8, return_value=0x2aa0179598,
    extra=0x2aa0174720) at worker_proc.cpp:764
#9  0x0000002a9bed9474 in zif_ral (ht=4, return_value=0x2aa0179598, return_value_ptr=0x0, this_ptr=0x0, return_value_used=1) at camel.cpp:331
#10 0x0000002a98bc0b24 in xdebug_execute_internal (current_execute_data=0x7fbfff9750, return_value_used=1)
    at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1339
#11 0x0000000000767d90 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fbfff9750)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:202
#12 0x000000000076739f in execute (op_array=0x2aa017a710) at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:92
#13 0x0000002a98bc0800 in xdebug_execute (op_array=0x2aa017a710) at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1272
#14 0x000000000073b37b in zend_call_function (fci=0x7fbfff9a20, fci_cache=Variable "fci_cache" is not available.
)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_execute_API.c:1049
#15 0x000000000075b2cb in zend_call_method (object_pp=0x7fbfff9ae0, obj_ce=0x2aa0178bf0, fn_proxy=0x2aa0178dd0, function_name=0xc7c52f "__call", function_name_len=6,
    retval_ptr_ptr=0x7fbfff9ae8, param_count=729840304, arg1=0x2aa016d948, arg2=0x2aa016c948)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_interfaces.c:88
#16 0x0000000000763389 in zend_std_call_user_call (ht=Variable "ht" is not available.
)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_object_handlers.c:673
#17 0x0000002a98bc0b24 in xdebug_execute_internal (current_execute_data=0x7fbfff9d00, return_value_used=1)
    at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1339
#18 0x0000000000767d90 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fbfff9d00)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:202
#19 0x000000000076739f in execute (op_array=0x2aa01729c8) at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:92
#20 0x0000002a98bc0800 in xdebug_execute (op_array=0x2aa01729c8) at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1272
#21 0x000000000076765c in zend_do_fcall_common_helper_SPEC (execute_data=0x7fbfff9fe0)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:234
#22 0x000000000076739f in execute (op_array=0x2aa0166b80) at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:92
#23 0x0000002a98bc0800 in xdebug_execute (op_array=0x2aa0166b80) at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1272
#24 0x000000000073b37b in zend_call_function (fci=0x7fbfffa250, fci_cache=Variable "fci_cache" is not available.
)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_execute_API.c:1049
#25 0x000000000073c2b6 in call_user_function_ex (function_table=Variable "function_table" is not available.
)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_execute_API.c:650
#26 0x0000000000696881 in zif_call_user_func_array (ht=Variable "ht" is not available.
)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/ext/standard/basic_functions.c:5217
#27 0x0000002a98bc0b24 in xdebug_execute_internal (current_execute_data=0x7fbfffa510, return_value_used=1)
    at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1339
#28 0x0000000000767d90 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fbfffa510)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:202
---Type <return> to continue, or q <return> to quit---
#29 0x000000000076739f in execute (op_array=0x2aa016cc70) at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:92
#30 0x0000002a98bc0800 in xdebug_execute (op_array=0x2aa016cc70) at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1272
#31 0x000000000076765c in zend_do_fcall_common_helper_SPEC (execute_data=0x7fbfffa7a0)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:234
#32 0x000000000076739f in execute (op_array=0x2a9ff05740) at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:92
#33 0x0000002a98bc0800 in xdebug_execute (op_array=0x2a9ff05740) at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1272
#34 0x000000000076765c in zend_do_fcall_common_helper_SPEC (execute_data=0x7fbfffaa00)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:234
#35 0x000000000076739f in execute (op_array=0x2a9ff19428) at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:92
#36 0x0000002a98bc0800 in xdebug_execute (op_array=0x2a9ff19428) at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1272
#37 0x000000000073b37b in zend_call_function (fci=0x7fbfffacd0, fci_cache=Variable "fci_cache" is not available.
)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_execute_API.c:1049
#38 0x000000000075b2cb in zend_call_method (object_pp=0x7fbfffadc0, obj_ce=0x2a9ff05430, fn_proxy=0x0, function_name=0x2a98d14a27 "execute", function_name_len=7,
    retval_ptr_ptr=0x7fbfffade0, param_count=729840304, arg1=0x0, arg2=0x0)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_interfaces.c:88
#39 0x0000002a98cfe3ae in ap_dispatcher_handle (dispatcher=0x2a95c36c40, request=0x2a95c3b2e0, response=0x2a95c3efd0, view=0x2a9fefd6d0)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php-ap_1-1-1-0_PD_BL/output/ap_dispatcher.c:683
#40 0x0000002a98cfea5c in ap_dispatcher_dispatch (dispatcher=0x2a95c36c40)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php-ap_1-1-1-0_PD_BL/output/ap_dispatcher.c:878
#41 0x0000002a98cfbb5d in zim_ap_application_run (ht=Variable "ht" is not available.
) at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php-ap_1-1-1-0_PD_BL/output/ap_application.c:438
#42 0x0000002a98bc0b24 in xdebug_execute_internal (current_execute_data=0x7fbfffb0e0, return_value_used=0)
    at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1339
#43 0x0000000000767d90 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fbfffb0e0)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:202
#44 0x000000000076739f in execute (op_array=0x2a95c34990) at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:92
#45 0x0000002a98bc0800 in xdebug_execute (op_array=0x2a95c34990) at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1272
#46 0x0000000000749128 in zend_execute_scripts (type=8, retval=0x0, file_count=3)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend.c:1134
#47 0x00000000007080c6 in php_execute_script (primary_file=0x7fbffffa80)
    at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/main/main.c:2037
#48 0x00000000007d7494 in main (argc=4, argv=0x7fbffffbd8) at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/sapi/cgi/cgi_main.c:2120
5、Using command f could select and print a stack frame.
1
(gdb) f 30
1
2
#30 0x00000000007672df in execute (op_array=0x2aa00101f8) at /home/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:92
92  in /home/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h
6、Using command p could print val
1
(gdb) p *op_array
1
2
3
4
5
$8 = {type = 2 '\002', function_name = 0x2a9f32e520 "process", scope = 0x2aa000fe80, fn_flags = 66048, prototype = 0x0, num_args = 2, required_num_args = 2, arg_info = 0x2a9f32e4b0, 
  pass_rest_by_reference = 0 '\0', return_reference = 0 '\0', refcount = 0x2a98ab0450, opcodes = 0x2a9f32e528, last = 512, size = 512, vars = 0x2a9f33d8a8, last_var = 17, size_var = 0, T = 34, 
  brk_cont_array = 0x2a9f33d828, last_brk_cont = 8, current_brk_cont = 4294967295, try_catch_array = 0x0, last_try_catch = 0, static_variables = 0x0, start_op = 0x0, backpatch_count = 0, 
  done_pass_two = 1 '\001', uses_this = 0 '\0', filename = 0x2a9f32e069 "/home/app/webapp/models/service/page/user/WebIndex.php", line_start = 19, line_end = 205, doc_comment = 0x0, 
  doc_comment_len = 0, reserved = {0x0, 0x0, 0x0, 0x0}}


How to change the path to the active Xcode installation for your machine

I updated my Mac OS X to 10.8GM today. Everything was fine. And then update Xcode to 4.4GM for 4.3 doesn’t support 10.8. I made a mistake that I run Xcode.app in dmg file. Then a setup wizard showed up. I press next next next… Suddenly I remind I should move the app to Application folder first. But the setup wizard can’t show up again. And the path of xcode had be set to /Volumes/Xcode.app/…
How to change it to the right path? I googled it there is a command named xcode-select.

$ xcode-select
xcode-select: Error: no command option given.

xcode-select: Report or change the path to the active
Xcode installation for this machine.

Usage: xcode-select –print-path
Prints the path of the active Xcode folder
or: xcode-select –switch Sets the path for the active Xcode folder
or: xcode-select –version
Prints the version of xcode-select

$ xcode-select --print-path
/Volumes/Xcode/Xcode44-DP7.app/Contents/Developer
$ sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/
Everything goes fine now.


How to develop Mac OS X apps using HTML5

HTML5 is very popular now. Lots of apps in mobile using HTML5 framework like PhoneGap, Sencha, Trigger, jQueryMobile…
If you want to develop Mac apps, you have to learn Objective-C and cocoa. But it is difficult for a beginner or web designer. So how about using HTML5? We can add a WebView on the app and display local html in it.
Let’s start!

1. Create a Mac OS X Cocoa Application
Find it in XCode -> File -> New -> Project -> Mac OS X Application -> Cocoa Application

2. Add [WebKit.framework] in your [Link Binary With Libraries].

3. Copy your web files like .html, .js, images to your project. If you can’t see them in your XCode, you should drop them from Finder to XCode.
I did some tests. These web files should be used like in the same path. I think it’s because the files in [Copy Bundle Resources] of [Build Phases] are in the same level.

4. Open your MainMenu.xib and drop a WebView in the interface. Make the size suit your app.

5. Link the WebView to your AppDelegate.h. The code in AppDelegate.h:

1
2
3
4
5
6
7
8
9
10
11
12
#import "Cocoa/Cocoa.h"
#import "WebKit/WebKit.h"

@interface AppDelegate : NSObject {
NSWindow *window;
IBOutlet WebView *webView;
}

@property (assign) IBOutlet NSWindow *window;
@property (nonatomic, retain) IBOutlet WebView *webView;

@end
6. Open your web htm file when the app start. Insert the open file code in AppDelegate.m:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#import "AppDelegate.h"

@implementation AppDelegate

@synthesize window;
@synthesize webView;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
}

- (void)awakeFromNib {
NSString *resourcesPath = [[NSBundle mainBundle] resourcePath];
NSString *htmlPath = [resourcesPath stringByAppendingString:@"/aero.html"];
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlPath]]];
}
@end

That’s it. Running like a native app.


ios

How to deploy app to your iOS device without certificate key

As we all know, it’s cost $99 to become a apple developer. But sometimes we have to make sure the app is ready. So how to deploy app before we have a certificate private key? Here we go!

My test environment is:

1、Macbook Air 2011 13'' + Mac OS X Lion 10.7.4 + XCode 4.3.2 + iOS SDK 5.1
2、iPad 1 + iOS 5.0.1
First, modify your SDK setting
cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/

sudo vi SDKSettings.plist

Find the key named CODE_SIGNING_REQUIRED and change its value to NO

Second, modify your project setting

1、Select your project in the left [Project navigator]
2、Select the [PROJECT] or [TARGETS]
3、Select [Build Setting]
4、Change the [Code Signing Identity]'s children to [Don't Code Sign]

Third, connect your iOS device to your Mac. The version of iOS between my iPad(5.0) and SDK(5.1) is different, so your device will not show up. If then, you should change the [iOS Deployment Target] in [Build Setting] to your device’s version(mine is 5.0).

Finally, Select your device instead of the simulator and RUN.

Enjoy it!