10/26/2016

[php] 在 Mac 用ATOM / Visual Studio Code 為 php debug


依php版本安裝 xdebug
brew install homebrew/php/phpXX-xdebug

在 /usr/local/etc/php/{x.y}/conf.d/ext-xdebug.ini) 內加上
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_connect_back=1    # Not safe for production servers
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_autostart=true



  • ATOM

安裝 php-debug package
https://atom.io/packages/php-debug

用 Atom 打開 php 檔案後插入中斷點,接著選功能表 Packages > PHP-Debug > Toggle Debugging(ctrl + option + D)
執行到中斷行就可以了


  • VS Code

安裝 PHP Debug
https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug

用 VS Code 打開 php 檔案後插入中斷點,接著在畫面左邊選擇debug圖示
執行到中斷行就可以了



12/01/2015

[Mac] 解決 您要讓應用程式 XXX 接受傳入的網路連接嗎 一直跳出

方法1: 先關掉該app 設定→防火牆→進階→允許名單找到該app移掉 再打開app 同意 方法2: 開啟終端機輸入 (可以先輸入codesign -v 後把app檔拉到終端機畫面會自動產生路徑)
codesign -v /Applications/xxx.app
如果會有/Applications/xxx.app: a sealed resource is missing or invalid 就是得把app檔刪掉重新安裝

10/20/2015

[php] 實作callback


用名稱呼
function run1($callback)
{
 $callback('123');
}

function funA($val)
{
 echo 'funA:'.$val;
}

run1('by run1');//funA:by run1

用物件傳(推薦)
class ClassB
{
 public function funB($val){
  echo 'ClassB:funB:'.$val;
 }
}

function run2(ClassB $callable){
 $callable->funB('by run2');
}

run2(new ClassB());//ClassB:funB:by run2

6/25/2015

[Android] setClickListener in custom view

直接設 setClickListener 沒反應
要加上

    private OnClickListener listener;

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_UP) {
            if(listener != null) listener.onClick(this);
        }
        return super.dispatchTouchEvent(event);
    }


    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if(event.getAction() == KeyEvent.ACTION_UP && (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER || event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
            if(listener != null) listener.onClick(this);
        }
        return super.dispatchKeyEvent(event);
    }

    @Override
    public void setOnClickListener(OnClickListener listener) {
        this.listener = listener;
    }

6/04/2015

解決 Error:Execution failed for task 'preDexDebug'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command finished with non-zero exit value 1

解決 Error:Execution failed for task 'preDexDebug'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command  finished with non-zero exit value 1

  • 檢查 用到的 jar libs 內是不是有重復到的元件

support v4 之類的最容易衝到



  • 檢查 做jar時的jdk是不是夠高

有些像<>  catch中直接 catch(InterruptedException | InterruptedException e)
要用到jdk 1.7



  • 檢查 做jar時的jdk是不是太高
jar用1.8
project 只用1.7時
考慮jar重包成1.7以下或project升級成1.8以上

5/15/2015

[Android] 下拉更新 SwipeRefreshLayout

Layout Xml

                <android.support.v4.widget.SwipeRefreshLayout
                    android:id="@+id/laySwipe"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >

                        <ListView
                            ... />
                </android.support.v4.widget.SwipeRefreshLayout>



Java Code

OnRefreshListener onSwipeToRefresh = new OnRefreshListener() {
        @Override
        public void onRefresh() {
            laySwipe.setRefreshing(true);
            //dosomething
            laySwipe.setRefreshing(false);
        }
    };

((SwipeRefreshLayout)findViewById(R.id.laySwipe)).setOnRefreshListener(onSwipeToRefresh);


幫listview補上下面的code避免滑動衝突


    private OnScrollListener onListScroll = new OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {
            if (firstVisibleItem == 0) {
                laySwipe.setEnabled(true);
            }else{
                laySwipe.setEnabled(false);
            }
        }
    };

4/21/2015

[Android] 處理 Can't create handler inside thread that has not called Looper.prepare()


因為 UI 操作不能在其它 thread 做
直接用 activity 提供的 runOnUiThread 做掉

runOnUiThread(new Runnable(){ public void run(){ 
    //原本會報錯的ui操作
});

8/21/2014

[Unity] uGUI (4.6) EventSystem 事件系統 快速上手

4.6 新進的 EventSystem 事件系統 可以用在 UI 事件外也可以用在普通的 GameObject
終於不用自已打射線偵測點擊了

環境 4.6.0b17 因為才beta版所以變動的機率很大


  • 對 UI 偵聽事件:

這邊先用 Image 試

4/29/2014

[Unity] Assetbundle Shader 遺失的解決方案

物件打包成 AssetBundle 後有的物件上的材質的shader 會 lost 變一塊紫色

//assetbundle後shader會lost的處理
gameObject.renderer.material.shader =  Shader.Find(gameObject.renderer.material.shader.name); 

或是

    using UnityEngine;
    using System.Collections;
    public class ApplyShader : MonoBehaviour 
    {
        private Material[] thisMaterial;
        private string[] shaders;
        void Start () {
            thisMaterial = this.renderer.sharedMaterials;             
            shaders =  new string[thisMaterial.Length];
            for( int i = 0; i < thisMaterial.Length; i++){
                shaders[i] = thisMaterial[i].shader.name;
            }    

            for( int i = 0; i < thisMaterial.Length; i++){
                thisMaterial[i].shader = Shader.Find(shaders[i]);  
            }
        }
    }

3/21/2014

[MAC] 在 MAC 上安裝 nginx

安裝 Homebrew
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
安裝 nginx
brew install nginx
讓 nginx 在登入時自動載入
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
立刻載入
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

sudo nginx
網頁根目錄
/usr/local/var/www
nginx 的設定檔
/usr/local/etc/nginx/nginx.conf
關掉 apache
sudo apachectl stop

2/21/2014

2/20/2014

[iOS開發] UIImageView 加點擊範例

簡單的讓 UIImageView 變成 ImageButton imgBtn.png 放在 Resources 資料夾
//生成 UIImage 並指定圖片
UIImage *image = [UIImage imageNamed:@"imgBtn.png"];
UIImageView *iv = [[UIImageView alloc] initWithImage:image];
//指定位置 x,y,width,height
iv.frame = CGRectMake(10, 10, image.size.width, image.size.height);

//讓 UIImage 能接受使用者事件
iv.userInteractionEnabled = YES;

//UITapGestureRecognizer 是觸控控制類
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected)];
singleTap.numberOfTapsRequired = 1;
[iv addGestureRecognizer:singleTap];

[self.view addSubview:iv];

-(void)tapDetected{
  NSLog(@"Click!!");
}

2/16/2014

[Android] 開啟另一個Activity


開啟另一個Activity ( A 呼 B
Intent intent = new Intent();
intent.setClass(A.this, B.class);
startActivity(intent);

不同 Activity 之間傳值